perf: optimize render-to-output text writing using replaceAt#124
Open
jacob314 wants to merge 2 commits into
Open
perf: optimize render-to-output text writing using replaceAt#124jacob314 wants to merge 2 commits into
jacob314 wants to merge 2 commits into
Conversation
bc9909d to
f245304
Compare
- Fix bug where zero-width characters (e.g., zero-width space) at the start of a chunk would consume a visual column and cause layout shifts. - Optimize `clearRange` by using `StyledLine.empty(len)` for spaces without background colors. - Add regression tests and update snapshots for zero-width characters.
73facdc to
1faae5e
Compare
cocosheng-g
approved these changes
Apr 15, 2026
|
|
||
| const left = this.slice(0, start); | ||
| const right = this.slice(end); | ||
| const combined = left.combine(slicedChars, right); |
Collaborator
There was a problem hiding this comment.
these create 3 new instances, maybe more efficient by directly mutate this.charData and this.spans using splice or direct index updates?
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.
This commit introduces performance optimizations for the renderer by using
replaceAtandcombineinOutputto reduce string allocations andlooping overhead. With these optimizations, the frame rate for
examples/nested-static/increases from 12 to 15 FPS.Additional fixes and optimizations:
applyWritewherezero-width characters (e.g., zero-width spaces, combining characters) at
the start of a slice chunk would incorrectly consume a visual column and
cause a layout shift.
clearRange: Leverages theStyledLine.empty(len)cache whenclearing spaces without a background color, avoiding unnecessary
allocations and looping.
(
test.serial) intest/multi-char-text.tsxto prevent race conditionscaused by global
currentStringWidthstate mutations.