Skip to content

perf(highlight-stream): avoid full highlighted rebuild every frame - #483

Merged
metonym merged 1 commit into
metonym:masterfrom
ljodea:perf/stream-incremental-highlighted
Jul 30, 2026
Merged

perf(highlight-stream): avoid full highlighted rebuild every frame#483
metonym merged 1 commit into
metonym:masterfrom
ljodea:perf/stream-incremental-highlighted

Conversation

@ljodea

@ljodea ljodea commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • While streaming, each animation frame rebuilt the full highlighted string (sealed prefix + tail) for the highlight event.
  • That is O(n) per frame and O(n²) over a growing stream, even though the DOM already paints sealed chunks incrementally.
  • Completed line HTML is appended once as lines finalize. The event payload is rematerialized only when completed lines change, on SSR, or on the final done pass. Preview-only frames reuse the previous payload; split rendering still paints the live tail.

Test plan

  • bun test tests/stream-highlighted.test.ts (append-only buffer + rematerialize policy)

… events

Completed line HTML is appended once as lines finalize. Each repaint
still assembles highlighted from completed + preview so on:highlight
stays current mid-line, without rebuilding the completed prefix from
sealed DOM chunks. Adds a no-newline streaming e2e that asserts the
event payload grows before done.
@metonym
metonym force-pushed the perf/stream-incremental-highlighted branch from c97c33c to a7c9f0c Compare July 30, 2026 05:05
@metonym
metonym merged commit b55216b into metonym:master Jul 30, 2026
2 of 3 checks passed
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