Skip to content

Avoid redundant redraw requests in native run loop - #8341

Open
rustbasic wants to merge 12 commits into
emilk:mainfrom
rustbasic:p107
Open

Avoid redundant redraw requests in native run loop#8341
rustbasic wants to merge 12 commits into
emilk:mainfrom
rustbasic:p107

Conversation

@rustbasic

@rustbasic rustbasic commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Avoid redundant redraw requests in native run loop

Summary

Avoid repeatedly requesting redraws for the same native window while a previous
request_redraw() is still pending.

Details

request_redraw() schedules a future WindowEvent::RedrawRequested. In reactive
apps, repeatedly calling request_redraw() before that event is delivered can
keep the event loop unnecessarily busy.

This PR adds per-window pending redraw tracking:

  • mark a window as pending when request_redraw() is called
  • skip additional redraw requests while pending
  • clear the pending state on WindowEvent::RedrawRequested
  • clear it for invisible/minimized windows that are painted directly

The run loop now also falls back to ControlFlow::Wait when there is no next
scheduled repaint, instead of relying on ControlFlow::Poll.

This should reduce redundant redraw requests and unnecessary CPU usage in
reactive native applications.

@github-actions

github-actions Bot commented Jul 25, 2026

Copy link
Copy Markdown

Preview available at https://egui-pr-preview.github.io/pr/8341-p107
Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.

View snapshot changes at kitdiff

@rustbasic rustbasic closed this Jul 26, 2026
@rustbasic

rustbasic commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

The fact that the deferred viewport fails to redraw when the ROOT viewport is clicked is an existing bug and is unrelated to this PR.

Solved :

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant