Fix high CPU usage when window is occluded on macOS #1003
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
My app is used a lot in the background, and I noticed high CPU usage in the native macOS version. With this PR, CPU usage is reduced when window is invisible by disabling drawing. This was already implemented for the JVM, and that behaviour is now copied to native macOS. So the code is similar to JVM parts in:
The draw function is now suspend, which required moving some other functions around. I tried to keep the implementation similar to the JVM version.
Testing
Tested using
./gradlew runNative
insamples/SkiaMultiplatformSample
. Now the CPU usage is reduced a lot when moving another (non transparent) app over the window.Old behaviour
Screen.Recording.2024-12-09.at.17.23.28.mov
New behaviour with 300ms timeout
See reduction in CPU usage when window is invisible
Screen.Recording.2024-12-09.at.17.26.17.mov
New behaviour without 300ms timeout
Screen.Recording.2024-12-11.at.23.27.20.mov