-
Notifications
You must be signed in to change notification settings - Fork 572
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
macOS: QuickTerminal under certain circumstances spins at 100% CPU #3998
Comments
We should flag a pending sync appearance and wait for the window to become visible (via notifications) to apply it. |
Hi, I was just visiting through the code trying to understand the bug what I believe we should check again if self is still valid before calling syncAppearance
|
That would probably work but if we can avoid queueing up multiple that'd be ideal, so I think we should fix this in a more robust way. |
Yes, correct then using the flag to prevent queuing multiple sync calls and avoiding unnecessary CPU usage spikes would be ideal. |
I observed this behavior and called it here #3742, however I didn't thought it was that bad and was hoping to get some feedback to address it directly in the PR. However, @mitchellh, I can understand if you prefer to address the performance issue separately. EDIT: Well, I opened #4055. |
Hmm, does this code change any behaviour? as the original code |
Yes you are correct although this does not explicitly change any code behavior but this will help maintain readability and avoid multiple calls ( if we need to perform multiple actions that depend on self, using if let self avoids repeating self? ). |
# Description The following code is causing an infinite loop that causes a CPU spikes until the quick terminal is displayed: https://github.com/ghostty-org/ghostty/blob/87bd0bb744d6a1c45022aa39f21219d0b6ff3261/macos/Sources/Features/QuickTerminal/QuickTerminalController.swift#L314-L317 ## Reproduce steps 1. Open Ghostty. 2. Open the Quick Terminal. 3. Close the Quick Terminal. 4. Reload the configuration (Ghostty > Reload Configuration or `shift+cmd+,`). 5. Observe CPU spike. ## Fix Now, `syncAppearance` doesn't postpone the process until it can be consumed, and the appearance is synchronized once the animation is done and the quick terminal is visible. Fixes #3998
Discussed in #3723
Originally posted by stuartcarnie December 28, 2024
Noticed that Ghostty was using 100% CPU, so I grabbed a CPU profile under Instruments and found that the hottest call stack was related to the Quick Terminal feature:
When I drill into that stack,
QuickTerminalController.syncAppearance
is a hot function. I currently don't have the window open, and I believe the culprit is this code:ghostty/macos/Sources/Features/QuickTerminal/QuickTerminalController.swift
Lines 310 to 318 in 196af6f
Given the window isn't open, this will repeatedly call the
syncAppearance
function.To re-trigger the high CPU usage, force a reload of your configuration and watch it spike again.
The text was updated successfully, but these errors were encountered: