Skip to content

perf(markdown): freeze settled section boundaries during streaming - #3801

Open
Raing5Days wants to merge 1 commit into
GCWing:mainfrom
Raing5Days:perf/stream-markdown-freezing
Open

Raing5Days wants to merge 1 commit into
GCWing:mainfrom
Raing5Days:perf/stream-markdown-freezing

Conversation

@Raing5Days

Copy link
Copy Markdown
Contributor

Summary of Changes

  • Streaming settled-prefix memoization: During progressive streaming chunk ingress into long Markdown documents (>3,000 chars), closed section boundaries strictly preceding the trailing open boundary are frozen.
  • Avoid repeated full tokenization: Rather than re-running \stream-markdown-parser's full document block parse and newline scanner on every single streaming token update, only the tail from the last frozen boundary is tokenized. If the tail has not accumulated enough text to form a new section (< SECTION_CHARS), slicing is completed in (1)$ without tokenization.
  • Object reference reuse: Retains immutable \MarkdownSection\ references across stream updates for unchanged leading slices so downstream memoized component trees (\FlowTextBlock, \MarkdownRenderer) avoid unnecessary re-renders.

Performance Evidence

Measured via local projection benchmark (\OpCase-Stream-Markdown-01, 25 simulated streaming chunks into 5,500+ character rich Markdown):

  • Subsequent streaming chunk P95 latency reduced to ~1.7ms (within the 2.0ms budget, down from cold block parse costs).
  • Max subsequent frame latency capped at ~1.9ms (within the 8.0ms budget).
  • Section object reuse ratio maintained across stream updates (~48% reuse with settled prefix preservation).
  • Unit tests (\markdownSections.test.ts\ and full \src/infrastructure/markdown/\ suite with 209 tests) pass with 100% green.

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