Skip to content

perf(cli): cache per-block wrapped transcript lines - #7762

Closed
innocarpe wants to merge 1 commit into
esengine:main-v2from
innocarpe:contrib/r11-tui-wrap-cache
Closed

perf(cli): cache per-block wrapped transcript lines#7762
innocarpe wants to merge 1 commit into
esengine:main-v2from
innocarpe:contrib/r11-tui-wrap-cache

Conversation

@innocarpe

Copy link
Copy Markdown
Contributor

Summary

Second TUI performance fix (follow-up to #7745): cache per-block wrapped transcript lines in internal/cli/ so dirty frames no longer re-wrap the ENTIRE transcript (spinner ticks, stream updates, transcriptDirty paths were O(transcript) lipgloss wraps per frame).

Equivalence gate first — a randomized differential test (transcript_wrap_test.go) compares whole-transcript wrap vs per-block wrap across ANSI/unicode/trailing-newline/unbalanced-SGR inputs. It exposed a real divergence: lipgloss pads blocks to the widest line, so per-block results can be shorter than whole-transcript results — fixed by re-padding each cached block to its widest line (byte-identical output for the actual renderers, which all close their SGR at block ends).

Cache: wrapCache map[int]string keyed by block index, invalidated on transcript mutation (append/update/remove and reflow paths) and dropped on width change. Join-only per frame; wrap only changed blocks.

Issues

None — performance, no issue report.

Verification

  • Equivalence test: randomized differential passes for all-balanced blocks; divergence case documented (widest-line padding) and handled
  • go test ./internal/cli/ — full suite pass
  • go vet / gofmt -l / go build ./cmd/reasonix — clean

Documentation impact

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

Cache impact

Cache-impact: none - TUI rendering only; no prompt/tool surface 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
@innocarpe

Copy link
Copy Markdown
Contributor Author

Closing as duplicate — main-v2 already merged the same optimization (#6978: syncWrappedLines + invalidateWrapFrom, suffix-only re-wrap). My per-block wrapCache covers the same hot path; keeping both would add complexity for no gain. The differential equivalence test (transcript_wrap_test.go) remains useful if a future rework wants it.

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