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

Identify and reduce background CPU usage #273

Open
4 of 5 tasks
Tyrrrz opened this issue Mar 28, 2024 · 3 comments
Open
4 of 5 tasks

Identify and reduce background CPU usage #273

Tyrrrz opened this issue Mar 28, 2024 · 3 comments

Comments

@Tyrrrz
Copy link
Owner

Tyrrrz commented Mar 28, 2024

Version

v2.4.7 / v2.5*

Platform

Windows 11

Steps to reproduce

Start LightBulb and hide it to the tray.

Details

Observe passive CPU usage of 0.1-1%, depending on the environment.

Need to identify the largest contributors to CPU usage and come up with a strategy to reduce it. Open for external contributions.

Related to #248, but split out into a separate issue to focus only on the CPU aspect because the relatively high RAM usage (50-70mb) is a byproduct of running on the .NET runtime and can't easily be resolved.

Checklist

  • I have looked through existing issues to make sure that this bug has not been reported before
  • I have provided a descriptive title for this issue
  • I have made sure that this bug is reproducible on the latest version of the application
  • I have provided all the information needed to reproduce this bug as efficiently as possible
  • I have sponsored this project
@seapat
Copy link

seapat commented Apr 2, 2024

Maybe, implementing a separate process could solve this?

(Windows-Auto-Night-Mode)[https://github.com/AutoDarkMode/Windows-Auto-Night-Mode/tree/master] seems to do it that way. AutoDarkModeSvc.exe runs constantly, when opening the app from the tray icon, AutoDarkModeApp.exe spawns as a separate process.

I have no experience with Windows app development, so I am unsure if that really would help (maybe with the ram consumption in #248 ?). Obviously, rewriting the app takes some considerable effort, which might not be worth it.

@Tyrrrz
Copy link
Owner Author

Tyrrrz commented Apr 3, 2024

Maybe, implementing a separate process could solve this?

(Windows-Auto-Night-Mode)[https://github.com/AutoDarkMode/Windows-Auto-Night-Mode/tree/master] seems to do it that way. AutoDarkModeSvc.exe runs constantly, when opening the app from the tray icon, AutoDarkModeApp.exe spawns as a separate process.

I have no experience with Windows app development, so I am unsure if that really would help (maybe with the ram consumption in #248 ?). Obviously, rewriting the app takes some considerable effort, which might not be worth it.

It could help, but first need to figure out what's even contributing to the CPU usage in the first place, to understand which areas need optimization.

@LilithSilver
Copy link
Contributor

From some quick profiling, it looks like the vast majority of the background CPU usage comes from Avalonia's main render loop, with no traceable path to any code LightBulb seems to be calling.

image

LightBulb's internal modules only have 2% of the total CPU usage compared to Avalonia's >80%.

In terms of memory usage, I'm seeing about 150-200mb on my machine, the vast majority of which is Avalonia components:

image

I agree with @seapat, I think the solution here is to split off the backend into a separate process and only run the frontend when requested. I think that'll solve 99% of the memory and CPU issues.

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

No branches or pull requests

3 participants