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

Fix issues with High CPU Usage on background #3278

Merged
merged 19 commits into from
Feb 9, 2025
Merged

Conversation

marticliment
Copy link
Owner

@marticliment marticliment commented Feb 7, 2025

There is an issue that has happened since UniGetUI (then WingetUI) was migrated to WinUI3/AppSdk: There is a permanent ~1%ish CPU usage that won't go away. This is no big deal desktop PCs unless you have an old machine, but laptops suffer from battery drain and overheating when closed due to this issue (I experience this on my own laptop). Looking at Process Explorer, I realized this CPU was used by some WinUI dwmapi.dll thread, and not by any UniGetUI component.
There are lots of open issues on microsoft/ui-xaml, such as this one: microsoft/microsoft-ui-xaml#9703

After some testing, I found out that suspending the thread automatically freezes the window, but my code is actually still running, the frozen part is only the renderer. Therefore, why not suspend the renderer when UniGetUI is running on the background, and unfreeze it when the window shows again?

This is what this PR does: Freeze the render thread on window hide, and unfreeze it on window show.
I don't know how stable this code will be. It is a proof of concept that will (probably) be tested by prerelease users, and perhaps introduced partially into stable at some point.

The suspended threads are:

  • dwmcoreapi.dll+0x54F70
  • Microsoft.UI.Xaml.dll!XamlCheckProcessRequirements+0x539b0 (represented by Microsoft.UI.Xaml.dll+0x5B1F0)

This feature can be disabled from the Settings Window, under Experimental Features.

fix #2049

@marticliment marticliment marked this pull request as ready for review February 8, 2025 23:54
@marticliment marticliment merged commit f4e466f into main Feb 9, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant