Skip to content

perf(cli): coalesce wheel scrolls and throttle stream flushes - #7745

Open
innocarpe wants to merge 1 commit into
esengine:main-v2from
innocarpe:contrib/r10-tui-scroll-perf
Open

perf(cli): coalesce wheel scrolls and throttle stream flushes#7745
innocarpe wants to merge 1 commit into
esengine:main-v2from
innocarpe:contrib/r10-tui-scroll-perf

Conversation

@innocarpe

Copy link
Copy Markdown
Contributor

Summary

Fix TUI scroll jank in long sessions (user-reported: scrolling stutters badly as transcripts grow; other terminal tools don't). An audit of internal/cli/chat_tui.go pinned two dominant bottlenecks; both are fixed behavior-preservingly:

B1 — wheel events caused a full-screen ClearScreen + full repaint per notch, uncoalesced (fast wheels/trackpad inertia = 30-120+ events/sec → dozens of full repaints/sec, defeating bubbletea's line-diff optimization):

  • Wheel deltas now accumulate (wheelAccum) and are applied once per 16ms tick (wheelScrollTick), one ScrollUp/Down of accum × 3 rows — same scroll semantics, ~10-50× fewer scroll commands/repaints
  • PgUp/PgDn, scrollbar drag, composer wheel, and the Warp tea.ClearScreen path are untouched

B2 — every stream flush re-rendered the ENTIRE accumulated answer with goldmark (up to several full re-renders per 512-event drain → O(answer²)):

  • Flushes are now throttled to one per 80ms window (streamFlushDue + streamFlushTick); the deferred flush is guaranteed by the tick, so final output is byte-identical
  • commitPending (message end) unchanged

Both fixes are unit-tested with injected times / synthetic tick messages (no sleeps, no flakiness): TestApplyWheelDelta, TestWheelScrollCoalescesBurstIntoSingleTick, TestStreamFlushDueThrottlesWithinWindow, TestStreamAnswerThrottlesDeferredFlushes + 12 existing wheel tests updated to feed the synthetic tick.

Issues

None — user-reported performance issue (matches closed tracking issue #1829's transcript-growth slowdown class; the block-cache rewrite covered other paths but these two remained).

Verification

  • go test ./internal/cli/ — full suite pass
  • go vet ./internal/cli/ — clean
  • gofmt -l internal/cli/ — clean
  • go build ./cmd/reasonix — OK

Documentation impact

Documentation-impact: none - internal rendering performance; no behavior or docs change.

Cache impact

Cache-impact: none - TUI rendering only; no prompt/tool surface or serialization touched.
Cache-guard: N/A
System-prompt-review: N/A

@github-actions github-actions Bot added v2 Go rewrite (1.x) — main-v2 branch, active development tui Terminal UI / CLI (internal/cli, internal/control) labels Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tui Terminal UI / CLI (internal/cli, internal/control) v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant