Skip to content

fix: block until shutdown#133

Merged
ccgauche merged 1 commit intoccgauche:masterfrom
restalex:master
Feb 2, 2026
Merged

fix: block until shutdown#133
ccgauche merged 1 commit intoccgauche:masterfrom
restalex:master

Conversation

@restalex
Copy link
Contributor

@restalex restalex commented Jan 27, 2026

When updating ytermusic I saw a huge spike in cpu usage (from 0.2 % to 100 % CPU core usage).
I used samply for profiling and saw that most of it was because of the loop checking if the shutdown signal have been sent.
I wanted to return to an async function but I did not want to break the macOS run_window_handler and I assume that it is made that way for a reason.
Instead of refactoring everything again, I just placed 100ms sleep into the loop, which I think is a reasonable time for a shutdown procedure.
This is not perfect, but with that we obtain a similar performance than before.

EDIT: I've just noticed that should close issue #132 .

@ccgauche
Copy link
Owner

I added a wait until the app is killed. This will be faster to react than a wait and even lighter. But on some system the OS may say that the app isn't responding. (If you can check for that it would be perfect).

@restalex
Copy link
Contributor Author

I've tested (this time by stashing the previous modifications before) and there was a simple error compilation on the if condition. I've rewritten it and tested it. As expected we obtain better results than before. I did not thought of implementing a mutex, thanks for that!

@restalex restalex reopened this Jan 29, 2026
@restalex restalex changed the title fix: reduce linux CPU usage by adding a sleep to the shutdown polling fix: block until shutdown Jan 29, 2026
@ccgauche ccgauche merged commit 80239cb into ccgauche:master Feb 2, 2026
3 checks passed
@ccgauche
Copy link
Owner

ccgauche commented Feb 2, 2026

Thanks for the contribution!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants