Repository navigation
Performance degradation over time + accelerated repro #11799
Issue Descriptiontl;dr unfocus/focus ghostty in a loop, watch send-rights climb on one port in lsmp I noticed a significant gradual performance decline on an M3 max macbook with ghostty, safari, discord, and activity monitor and nothing else open. This first happened after not exiting ghostty for quite some time while doing ordinary work, so I started fishing for reasons why it might be slowing down. I also had a decent chunk of cpu time on the system spent in WindowServer (in compositing tasks, per Trying to see if I could reproduce the ghostty slowdown, I tried to think of things that I do in regular use which might provoke state changes — connecting and disconnecting external displays, sleeping and waking, alt-tabbing, copying/pasting, etc. I figured some of those I can artificially speed up, so I started with the easiest of those, alt-tabbing, and hit on something that looks legit. If you use applescript to slam unfocus/focus in a hot loop, you can pretty quickly reproduce the state I got in to. The only thing I was able to dig up poking at the process which pointed to resource exhaustion or leaking (I'm not exactly a macOS expert, linux is my day job) was what looks like an ever-growing number of send-rights on one mach port in lsmp for ghostty. Expected BehaviorIdeally not slow down Actual BehaviorThe whole system gets slow after a while of this abuse, in a way that doesn't seem to happen when doing the same to Safari or Apple's Terminal.app Reproduction Steps
As you go along, watch WindowServer's CPU load, and notice the frequency of flicker in window decoration focus display getting more uneven over time. Also note the system getting a little less predictably-instant doing things like switching focus to other applications (in between runs above, of course). After a couple rounds of this, I'm able to get WindowServer's cpu load up to the mid-60% (with nothing going in ghostty, just a shell waiting for input). When you quit ghostty, WindowServer's cpu load will drop, but not to a normal idle-system level (mine in my latest run of these steps went from 68% to ~25%, and back up to 30% when I reopened ghostty to idle it). Ghostty LogsGhostty VersionOS Version InformationmacOS Tahoe 26.3.1 (a) (Linux only) Display ServerNone (Linux only) Desktop Environment/Window ManagerNo response Minimal Ghostty ConfigurationN/A — I only have a theme and shell-integration-features=ssh-env, neither of which should be related.aAdditional Relevant ConfigurationNo response I acknowledge that:
EDIT: deleted redundancy — turns out typing on a machine that's slowed to a crawl is a bit of a struggle. |
Replies: 8 comments 9 replies
|
I haven't tried to reproduce this yet, but I appreciate the detailed response. Can I ask: do you have secure input enabled (within Ghostty, via the menu item in "Ghostty")? The fact this continues after quitting really smells like a macOS bug, but I'm interested in understand how we trigger that of course and how we can mitigate it. I'll try your repro soon! |
|
I've experienced this or something very much like it as well. Over time Ghostty gets slower to appear when triggered with the hotkey and WindowServer uses between ~10-40% CPU when doing very little. I've also noticed over time clicking between panes in Ghostty becomes less reliable, you might click to type in or select some text from one pane only to find that the pane was never activated.
I'm fairly certain that WindowServer has been very CPU heavy across macOS releases for many years (with or without Ghostty) and is heavily correlated to the resolution and number of external displays. I wouldn't be at all surprised if this was a bug in WindowServer which Ghostty exacerbates somehow. |
This comment was marked as low quality.
This comment was marked as low quality.
|
|
|
After six days of usage, I can confirm: the fix proposed in #13386 does truly resolve the WindowServer CPU issue. I've pushed it to a branch. Try it out: # Requires full Xcode
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
xcodebuild -downloadComponent MetalToolchain
mise install zig@0.16.0
git clone --branch fix-macos-transparent-titlebar-window-retention \
--single-branch https://github.com/mustafa0x/ghostty.git
cd ghostty
# Build; output is zig-out/Ghostty.app
mise exec zig@0.16.0 -- zig build -Doptimize=ReleaseFast
# Fully quit any existing Ghostty first, then launch the patched build
open "$PWD/zig-out/Ghostty.app"AI's explanation:
|
|
I've been experiencing the very same problem since March (1.3.1 release). At some point Ghostty starts creating new mac ports exactly every second: and then eventually gets killed by the kernel at reaching exactly 305836 ports: It happens every two-three days, I usually notice Ghostty is gone when waking macStudio after a sleep. I built the suggested branch locally and will give it a try. macOS and Ghostty are running 24.7 here with Ghostty usually having around 10-15 tabs running a few text file managers (far2l recently but happened with mc too). The good thing is that all far2l processes keep running after ghosty being killed and I can reattach to them after a restart but it's quite a headache when there are 10 of them. PS. No crash reports by Ghostty itself in |
|
@mitchellh thanks for quickly fixing it. What's the proper way to test it? Just build from master? I hope you will come up with a beta / nightly channel for macOS since it's always tricky to have a custom-built .app next to the official one, due to signing/permissions/etc. |
|
Just confirming, after two weeks, no kill issue at wakeup anymore. |
#13590