Skip to content

perf(tui): optimize markdown wrapping and render layout#2

Merged
igorsheg merged 12 commits into
mainfrom
autoresearch/tui-render-2026-05-16
May 16, 2026
Merged

perf(tui): optimize markdown wrapping and render layout#2
igorsheg merged 12 commits into
mainfrom
autoresearch/tui-render-2026-05-16

Conversation

@igorsheg
Copy link
Copy Markdown
Owner

@igorsheg igorsheg commented May 16, 2026

Summary

Optimizes TUI markdown/transcript rendering by removing redundant wrap width scans, reusing accumulated wrap widths, adding safe printable-ASCII width/slicing fast paths, and reducing small allocation churn in markdown span/layout construction.

The PR intentionally contains implementation changes only. Autoresearch scripts/logs and the temporary benchmark file were removed from the final diff.

Autoresearch result

  • Baseline: render_ms=376.128, rows=2519
  • Current: render_ms=68.557, rows=2519
  • Final validation run before artifact removal: render_ms=68.592, rows=2519
  • Speedup: ~5.49x
  • Runtime reduction: ~81.8%

Checks

  • zig build test

Notes

Unsafe grapheme-boundary ASCII fast path was rejected because it broke combining-mark clusters. Row-list preallocation was also rejected due benchmark regression. Kept changes are localized to safe width/wrap/render hot paths.

igorsheg added 12 commits May 16, 2026 18:59
…rk before optimization"},"metrics":{"rows":2519},"summary":"Baseline for large assistant markdown measure/render workload."}

Result: {"status":"keep","render_ms":376.128}
…e.strWidth avoids per-codepoint grapheme segmentation for common markdown/text spans."},"metrics":{"rows":2519},"summary":"Added safe printable ASCII fast path for strWidth only. Preserves grapheme boundary behavior and row count."}

Result: {"status":"keep","render_ms":114.826}
… in wrap.nextSegment avoids redundant full-line strWidth work; token accumulation already detects whether a line fits."},"metrics":{"rows":2519},"summary":"Removed redundant early full-line width scan from TUI wrap segmenter."}

Result: {"status":"keep","render_ms":101.08}
…_cols avoids redundant strWidth calls on common non-piece wrap returns."},"metrics":{"rows":2519},"summary":"Reused accumulated width in wrap segment returns; kept exact width calculation for hard-broken oversized tokens."}

Result: {"status":"keep","render_ms":84.549}
…repeated line-array growth during large markdown wrapping."},"metrics":{"rows":2519},"summary":"Added simple output line capacity estimate for display word wrapping."}

Result: {"status":"keep","render_ms":84.446}
…de/list fragments; bypassing ArrayList reconstruction reduces per-line allocation overhead."},"metrics":{"rows":2519},"summary":"Added single-run fast path for markdown span reconstruction."}

Result: {"status":"keep","render_ms":84.19}
…ction list avoids growth checks and reallocations for multi-run wrapped lines."},"metrics":{"rows":2519},"summary":"Preallocated small span lists in markdown reconstruction."}

Result: {"status":"keep","render_ms":84.109}
…mber of markdown spans avoids tiny growth reallocations in the transcript layout conversion."},"metrics":{"rows":2519},"summary":"Preallocated transcript layout segment lists from markdown span counts."}

Result: {"status":"keep","render_ms":84.002}
…ToWidth can return byte slices directly for printable ASCII instead of walking grapheme clusters."},"metrics":{"rows":2519},"summary":"Added printable-ASCII fast path to grapheme.sliceToWidth."}

Result: {"status":"keep","render_ms":68.557}
@igorsheg igorsheg merged commit 566fa48 into main May 16, 2026
3 checks passed
@igorsheg igorsheg deleted the autoresearch/tui-render-2026-05-16 branch May 16, 2026 16:24
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