Skip to content

fix(simulate): wrap only new log lines each frame - #932

Open
u9g wants to merge 1 commit into
mainfrom
u9g/simulate-log-wrap-cache
Open

fix(simulate): wrap only new log lines each frame#932
u9g wants to merge 1 commit into
mainfrom
u9g/simulate-log-wrap-cache

Conversation

@u9g

@u9g u9g commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

renderLogs re-wrapped the whole agent log history every frame to display height/3 lines, so cost scaled with total log volume (~7.6µs/line). With the log pane open (Ctrl+L) on a 100-job run that is ~900ms per View() against an 80ms spinner tick — the TUI drops to roughly one frame per second.

Measured View() at 160x45, 100 jobs:

log lines before after
1,000 8.3ms 0.3ms
15,000 113ms 0.3ms
50,000 380ms 0.3ms
120,000 ~900ms ~1ms

At 120k lines the RecentLogs(0) copy is 158µs and the lipgloss re-wrap is 917ms, so the wrap is the entire cost.

The whole-run buffer is append-only, so this caches the wrapped lines on the model and wraps only the new tail; a width change or a buffer shrink rebuilds. The per-room path (job detail view) is bounded by one conversation and is unchanged.

Verified byte-identical to the previous wrap-everything output across appends, scroll offsets, resizes and offset clamping.

renderLogs re-wrapped the entire agent log history on every frame to show
height/3 lines. At 120k lines that is ~900ms per View() against an 80ms
spinner tick, so the TUI dropped to about one frame per second with the log
pane open on a 100-job run.

Cache the wrapped whole-run log lines, keyed by wrap width, and wrap only
the newly appended tail. Measured 912ms -> 1ms at 120k lines; output is
byte-identical across appends, scroll offsets, resizes and offset clamping.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant