Skip to content

perf(ui): tail-render scrollback instead of full buffer#105

Merged
hyldmo merged 1 commit into
mainfrom
hyldmo/stream-logs-from-file
Apr 21, 2026
Merged

perf(ui): tail-render scrollback instead of full buffer#105
hyldmo merged 1 commit into
mainfrom
hyldmo/stream-logs-from-file

Conversation

@hyldmo
Copy link
Copy Markdown
Owner

@hyldmo hyldmo commented Apr 21, 2026

Summary

  • Old code reset the terminal at 50k lines / 10MB to stop getJson() from freezing the event loop on verbose processes. Scrollback vanished each reset.
  • New TailingTerminal subclass patches GhosttyTerminalRenderable._persistentTerminal.getJson to inject offset = totalLines - limit, so rendering always extracts only the tail window (RENDER_LIMIT = 5000). Render cost is O(limit) regardless of buffer size.
  • OOM backstop thresholds raised 20x (50k → 1M lines, 10MB → 500MB) since render cost no longer scales with buffer size.
  • Older lines remain in ghostty's native scrollback (unbounded). A follow-up phase will wire scroll-up offset to ScrollBox so users can page through pre-tail history.

Upstream tracking: remorses/ghostty-opentui#7

Test plan

  • 26 unit tests pass (bun test src/ui/pane.test.ts)
  • Full suite passes (660 tests)
  • Typecheck clean (bun run typecheck)
  • Lint clean (bun run lint)
  • Real-world: bun run dev against a noisy process (yes | head -200000); verify no freeze and tail lines visible

🤖 Generated with Claude Code

Old code reset the terminal at 50k lines / 10MB to stop getJson()
from freezing the event loop on verbose processes. Scrollback
vanished each time the cap was hit.

TailingTerminal subclasses GhosttyTerminalRenderable and patches
the underlying getJson to inject offset = totalLines - limit, so
each render extracts only the tail window (RENDER_LIMIT = 5000
lines) regardless of how much has been fed. Render cost is now
O(limit), not O(buffer). Older lines stay in ghostty's native
scrollback and will be reachable via scroll-up paging in a later
phase.

Raised OOM backstop thresholds 20x (50k to 1M lines, 10MB to
500MB) since render cost is no longer proportional to buffer
size. The line check now uses our newline counter since
terminal.lineCount is capped at RENDER_LIMIT.

Upstream tracking: remorses/ghostty-opentui#7

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@hyldmo hyldmo merged commit d07c245 into main Apr 21, 2026
2 checks passed
@hyldmo hyldmo deleted the hyldmo/stream-logs-from-file branch April 21, 2026 09:45
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 2.14.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant