Skip to content

perf: optimize render-to-output text writing using replaceAt#124

Open
jacob314 wants to merge 2 commits into
masterfrom
optiimize_replaceAt
Open

perf: optimize render-to-output text writing using replaceAt#124
jacob314 wants to merge 2 commits into
masterfrom
optiimize_replaceAt

Conversation

@jacob314

@jacob314 jacob314 commented Apr 15, 2026

Copy link
Copy Markdown
Owner

This commit introduces performance optimizations for the renderer by using
replaceAt and combine in Output to reduce string allocations and
looping overhead. With these optimizations, the frame rate for
examples/nested-static/ increases from 12 to 15 FPS.

Additional fixes and optimizations:

  • Fix zero-width character bug: Fixed a regression in applyWrite where
    zero-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.
  • Optimize clearRange: Leverages the StyledLine.empty(len) cache when
    clearing spaces without a background color, avoiding unnecessary
    allocations and looping.
  • Fix test flakiness: Changed parallel test execution to serial
    (test.serial) in test/multi-char-text.tsx to prevent race conditions
    caused by global currentStringWidth state mutations.

@jacob314 jacob314 force-pushed the optiimize_replaceAt branch from bc9909d to f245304 Compare April 15, 2026 16:16
- 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.
@jacob314 jacob314 force-pushed the optiimize_replaceAt branch from 73facdc to 1faae5e Compare April 15, 2026 18:32
@jacob314 jacob314 requested a review from cocosheng-g April 15, 2026 18:44
Comment thread src/styled-line.ts

const left = this.slice(0, start);
const right = this.slice(end);
const combined = left.combine(slicedChars, right);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these create 3 new instances, maybe more efficient by directly mutate this.charData and this.spans using splice or direct index updates?

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.

2 participants