perf(tui): optimize markdown wrapping and render layout#2
Merged
Conversation
…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}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
render_ms=376.128,rows=2519render_ms=68.557,rows=2519render_ms=68.592,rows=2519Checks
zig build testNotes
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.