Skip to content

Fix issues with High CPU Usage on background#3278

Merged
Martí Climent (marticliment) merged 19 commits intomainfrom
cpu-usage-fix
Feb 9, 2025
Merged

Fix issues with High CPU Usage on background#3278
Martí Climent (marticliment) merged 19 commits intomainfrom
cpu-usage-fix

Conversation

@marticliment
Copy link
Copy Markdown
Collaborator

@marticliment Martí Climent (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 Martí Climent (marticliment) marked this pull request as ready for review February 8, 2025 23:54
@marticliment Martí Climent (marticliment) merged commit f4e466f into main Feb 9, 2025
2 checks passed
@marticliment Martí Climent (marticliment) deleted the cpu-usage-fix branch February 21, 2025 15:26
@mrixner mrixner mentioned this pull request Mar 1, 2025
4 tasks
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.

[BUG] DDE Server Window: UniGetUI.exe - System Error (overrun of a stack-based buffer) [BUG] Winget eats 50% of my CPU when i close the notebook lid.

1 participant