Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On macOS and X11 do not render when the window is occluded for performance #6177

Merged
merged 2 commits into from
Aug 11, 2022

Conversation

trimental
Copy link
Contributor

@trimental trimental commented Jul 1, 2022

Rendering when the window is not visible due to it being closed, minimised, occluded by other windows, etc; is extremely cpu/gpu intensive with no benefit to the user.

By implementing occlusion detection, my simple bash script that prints numbers every 0.1 seconds went from ~10% cpu usage to about ~0.4% cpu usage when in the background. I've submitted a winit pull request but I thought I might as well get in early to show off the performance/efficiency benefits.

@trimental trimental force-pushed the macos-occlusion branch 2 times, most recently from 41ecaa5 to 40a29bb Compare July 2, 2022 10:19
@trimental trimental changed the title On macOS do not render when the window is occluded for performance On macOS and X11 do not render when the window is occluded for performance Jul 3, 2022
@trimental
Copy link
Contributor Author

Added X11 support

@kchibisov
Copy link
Member

@trimental Thanks for the PR, but I'd suggest to hold until #6079 since it contains all the changes required for upstream winit. I can apply your patch later, since we'll have rendering related patches as well and they affect the should_draw logic.

@christianparpart
Copy link

christianparpart commented Aug 6, 2022

FYI: Looks like Occluded also means when another window is above your window. I was checking the docs, but I may be wrong, so please correct me then.

Now, from first sight, it might not make sense to render. But what iff the window that's occluding you is actually semi-transparent. Then you'd show stale content. Having semi-transparent windows in 2022 isn't actually a too rare condition, because users seem to like that and configure their desktop as such (e.g. for file managers, or actually terminals, with and without blur effect).

If the window is actually hidden/symbolized, such an optimization makes 100% sense, but the occlusion due to other windows laying on top of you, I fear will generate confusion.

p.s.: forgot to mention, even when symbolized/hidden, the window might need to be rendered up-to-date because desktop's like to show you a preview when Alt Tab'ing through the windows, or even when simply hovering the mouse over the app window of a symbolized/hidden window. Can such an event be distinguished from? If not, I'd even say the whole idea is sadly not applicable.

@trimental
Copy link
Contributor Author

@christianparpart Yes you're completely right in all of those assumptions, ie we still need to render when the compositor is presenting previews or behind semi transparent windows.

On macOS both of these are 100% taken into account, so the window is only marked as occluded if it completely cannot be seen in any way. On x11 its a bit harder to know whether all compositors will remember to take care of this, but considering the x11 docs.

When the window changes state from viewable and completely unobscured, viewable and partially 
obscured, or not viewable to viewable and fully obscured, the X server generates the event with the 
state member of the XVisibilityEvent structure set to VisibilityFullyObscured.

I would definitely interpret that to mean all x11 compositors should account for transparency and previewing, although I haven't fully tested different X11 compositors

@kchibisov
Copy link
Member

@trimental the winit patch got merged. So you can rebase.

@trimental
Copy link
Contributor Author

@kchibisov done :)

alacritty/src/event.rs Outdated Show resolved Hide resolved
@kchibisov kchibisov merged commit 3763003 into alacritty:master Aug 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants