Tick libghostty on wakeup instead of a 120Hz timer#125
Merged
Conversation
GhosttyApp ran a 120Hz repeating timer calling ghostty_app_tick forever — 120 wakeups/sec even with the app hidden, the largest remaining idle cost after #115. The timer was redundant: libghostty's wakeup_cb already requests a tick whenever the core needs one (GhosttyCallbacks.wakeup schedules it on the main queue), which is how upstream Ghostty.app drives ticking. A 1s safety-net timer (0.5s tolerance) remains so a hypothetically missed wakeup degrades to a one-second-late tick instead of a wedged UI.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Replaces the unconditional 120Hz
ghostty_app_ticktimer with event-driven ticking via libghostty'swakeup_cb(already wired —GhosttyCallbacks.wakeupschedulestick()on the main queue), keeping a 1s safety-net timer so a missed wakeup degrades to a late tick rather than a wedged UI.Why
Profiling the post-#115/#123 idle residue showed the 120Hz timer is the largest remaining constant wakeup source — 120/sec even while hidden. Upstream libghostty's own contract is demand-driven: "Tick the event loop. This should be called whenever the 'wakeup' callback is invoked for the runtime" (src/apprt/embedded.zig). The fixed timer was never the intended mechanism; this makes Macterm follow the documented contract, the same way Ghostty.app does.
Verified
Measured head-to-head, debug builds, idle:
sampleGhosttyApp.swift:66,ghostty_app_tickfiring)mise run format,mise run lint,mise run testall passwakeup_cbis the intended on-demand tick driver, and confirmed thewakeup_cb → wakeup() → tick()path is intact and unconditionalNot yet observed live: a keypress→echo confirmation in the running app (my verification build launched with no project selected, so there was no surface to type into). The CPU win is measured and the wakeup contract is upstream-documented, but the empirical input loop is best confirmed by running this branch alongside #126 as a daily driver — a wedged terminal would be immediately obvious. Recommend merging together after that pass.
🤖 Generated with Claude Code