Poll foreground processes adaptively instead of at a fixed 250ms#126
Merged
Conversation
…ompletion Since #115 parks an occluded surface's renderer, hidden panes emit no render/scrollbar heartbeats. The status indicator's quiet-settle read that silence as "command finished" and flipped a still-running TUI in a hidden tab to a done checkmark — which sticks, because activity events can never revive a done pane. Settle now runs only while the pane's window is visible. On the occluded-to-visible edge the quiet window restarts, so a still-running program gets its heartbeats back before the 3s settle can fire. The occlusion probe is an injected closure (no window = occluded, covering incubator-hosted panes) so the behavior is unit-tested.
The unconditional 250ms poll was the app's last structural idle cost (~0.9% of a core, scaling with pane count — the residue of #110 after occlusion parking landed in #115). Polling fast is only useful while something is moving, and every interesting moment already announces itself: tab switches, keystrokes, OSC titles, and execution-state transitions. PollCadence (pure, clock-injected, fully unit-tested) picks the interval: 250ms during a 5s burst after any such event or while a command runs frontmost, 1s when the app is active but idle, 2s when inactive with a window visible (sidebar titles must not freeze), and no timer at all when nothing is on screen — events resume instantly, and polls fired by event storms coalesce to the fast interval. Title-pipeline guarantees survive: liveness is now event-bounded rather than interval-bounded, programTitle expiry rides the same refresh, and the quit dialog re-reads names one-shot because the poll may be paused when quitting from a minimized window.
# Conflicts: # Macterm/App/AppState.swift # MactermTests/App/AppStateTests.swift
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 250ms foreground-process poll with an adaptive cadence: 250ms only while something is moving, 1s when the app is active but idle, 2s when inactive with a window visible, and no timer at all when nothing is on screen.
Why
After #115 (occlusion parking) and #123 (occlusion settle guard), the fixed 250ms poll was the app's last structural idle cost — ~0.9% of a core, forever, scaling with pane count. Polling fast is only useful while something is moving, and every interesting moment already announces itself (tab switch, keystroke, OSC title, execution-state transition), so those drive an instant resume. This is the third and final piece of the #110 CPU story; a companion PR (#125) removes the 120Hz libghostty tick timer.
How
PollCadence(Macterm/App/PollCadence.swift): pure, clock-injected value type —Mode { fast, idle, background, paused }, aContextsnapshot,noteEvent/notePolled/mode/nextDelay. Event storms coalesce to the fast interval;notePolledbefore the tick's work breaks the poll→execution-transition→event recursion.AppStatedrives a single non-repeating rescheduledTimer(.commonmode, 10% tolerance) off the cadence, with injectedisAppActive/isAnyWindowVisibleclosures (the quick terminal's non-activating panel counts; the incubator's ordered-out window doesn't)..terminalPollEventfunnel posted from tab-select (Workspace), OSC title, user interaction, andexecutionStatetransitions (value-change only — no per-frame render spam). Plus app-activate/resign, occlusion-change, and wake observers.Verified
mise run format,mise run lint,mise run testall passPollCadenceunit tests: mode/interval table across contexts, burst decay, coalescing, resume-after-pause, quick-terminal-typing-while-inactive, storm capStacked on #123 (now merged); main merged in.
🤖 Generated with Claude Code