Skip to content

Long chat replies stream with less stutter: parse each block once - #34821

Merged
brennanb2025 merged 6 commits into
mainfrom
brennanb2025/nc-perf-md-parse
Oct 28, 2026
Merged

brennanb2025 merged 6 commits into
mainfrom
brennanb2025/nc-perf-md-parse

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​727 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​725
Prod 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​371 $\color{#cf222e}{\Huge{\mathbf{−}}}$​72 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​299

Performance and the common pattern

Status: final-head measurements. The rendering difference found in review is fixed and fresh correctness review passed. These values compare the final head with its merged-main baseline in four alternating run orders, with the native chat parser extensions installed. All seven workloads passed 3,430 exact-HTML comparisons; these are synchronous renderer measurements, not packaged frame-rate claims.

Workload (median / p95 per streaming update) Before After Change (median)
Short reply (800 characters) 0.79 / 1.49 ms 0.55 / 0.93 ms 1.4× faster
Growing paragraph (50k) 51.76 / 84.91 ms 32.16 / 60.01 ms 1.6× faster
Growing code fence (56k) 15.45 / 20.84 ms 8.30 / 10.37 ms 1.9× faster
Growing list (48k) 86.44 / 134.51 ms 60.17 / 105.92 ms 1.4× faster
Completed fence + short streaming tail 12.56 / 18.21 ms 0.73 / 1.60 ms 17× faster
Code fence with inert visual marker 18.25 / 23.15 ms 17.05 / 22.37 ms 1.1× faster
Completed fence → visual fallback 0.76 / 10.50 ms 0.60 / 9.89 ms 1.3× faster
Common pattern? Yes, with implementation differences. One common approach keeps a pristine parsed prefix through a safely closed code fence, parses what follows, and clones the prefix into a whole-document tree; this PR shares the reuse principle but keeps independently rendered blocks. Another common approach parses pieces to render them and reuses unchanged safe pieces, including completed fences; this PR instead retains raw trees and uses parser-derived boundaries. Both common approaches avoid reparsing settled content. This PR also reuses its block-discovery tree for rendering while preserving Orca's existing transform scope.

Long chat replies with large paragraphs, lists, or code blocks can stream slowly and make the app stutter because Orca parses the same text to find block boundaries and then parses it again to render it.

Reuse the first syntax tree for rendering, retain unchanged settled blocks, and stop rediscovering completed code fences while the following text streams. Rendering, copy text, word fade, code-block source lines, and reveal timing stay the same.

Workload Before median / p95 (ms) After median / p95 (ms)
Short reply (800 characters) 0.79 / 1.49 0.55 / 0.93
Growing paragraph (50k) 51.76 / 84.91 32.16 / 60.01
Growing code fence (56k) 15.45 / 20.84 8.30 / 10.37
Growing list (48k) 86.44 / 134.51 60.17 / 105.92
Completed fence + short tail 12.56 / 18.21 0.73 / 1.60

Measured with the production-pipeline harness on the same Mac, using the existing reveal cadence. Values are synchronous render-update latency, including discovery, transforms, React rendering, and DOM commit.

Plan: Remove duplicate parsing by adopting the common pattern: one configured parser supplies both block boundaries and the tree used by the existing rendering pipeline. Each render gets a pristine clone in block-local source coordinates, and parser configuration changes invalidate trees while preserving current cuts. HTML and definitions retain whole-document rendering. Repaired source, byte-order marks, and sliced indented openers intentionally retain their existing standalone parse because their parser inputs differ; this preserves exact output and source positions.

Validation: 308 tests passed across 20 named markdown/native-chat files. A differential test compares exact HTML, copy text, and code source-line attributes after every production reveal prefix, including all five workloads, lists/setext boundaries, HTML/definitions, math/repair, sanitized HTML, file links, word fade, indentation, and line endings. An actual-parser counter asserts one parse for discovery/render and tail-only parsing after a completed fence; the previous path parses more characters. All five original benchmark workloads passed. No reserved link-routing or math-cache files changed.

@brennanb2025
brennanb2025 marked this pull request as ready for review October 28, 2026 06:33
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fad221f6-533e-4412-bb54-74695724326c
Commits

Reviewing files that changed from the base of the PR and between 27ea22b and a0e0ac3.

Files selected for processing: 8
  • src/renderer/src/components/native-chat/NativeChatMarkdown.tsx
  • src/renderer/src/components/native-chat/NativeChatMarkdown.visual.test.tsx
  • src/renderer/src/components/native-chat/native-chat-visual-markdown-extension.tsx
  • src/renderer/src/components/sidebar/CommentMarkdown.parse-validity.test.tsx
  • src/renderer/src/components/sidebar/CommentMarkdown.tsx
  • src/renderer/src/components/sidebar/comment-markdown-block-pipeline.tsx
  • src/renderer/src/components/sidebar/markdown-parse-meter.test-fixture.ts
  • src/renderer/src/components/sidebar/markdown-top-level-blocks.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Walkthrough

The Markdown block splitter now accepts a parser callback and retains reusable block-local parse trees. CommentMarkdown builds the parser from active remark plugins and passes available trees to MemoizedMarkdown. Native-chat visual extensions provide extra flow-syntax markers. New tests compare incremental rendering with a legacy splitter and measure parsing and tree work across updates.

Priority: Normal

Merge Risk: Minimal · up to a0e0a

No identified issue blocks merging after normal checks.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 31.25% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check Warning The description provides detailed change rationale, performance data, implementation scope, and validation results, but it does not follow the required template. It omits the ELI5, What Changed, Why, … Rewrite the description using the repository template. Add the required headings, link the actual issue in “Fixes #”, provide before/after visual proof or state N/A with a reason, document manual and automated testing with platforms, comple…
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly states the primary change: reducing streaming stutter by parsing each Markdown block once.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 31.25% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 16 functions across 10 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Full details: Description check

Explanation

The description provides detailed change rationale, performance data, implementation scope, and validation results, but it does not follow the required template. It omits the ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, Review, Notes, and Checklist sections. No issue link or visual proof/N/A statement is provided.

Resolution

Rewrite the description using the repository template. Add the required headings, link the actual issue in “Fixes #”, provide before/after visual proof or state N/A with a reason, document manual and automated testing with platforms, complete the applicable checklist items, and add AI disclosure if applicable.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 5


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a7071c50-ac75-4308-8aa9-2cc9c57b071e
Commits

Reviewing files that changed from the base of the PR and between ff6a375 and 7e2478b.

Files selected for processing: 4
  • src/renderer/src/components/sidebar/CommentMarkdown.parse-reuse.test.tsx
  • src/renderer/src/components/sidebar/CommentMarkdown.tsx
  • src/renderer/src/components/sidebar/markdown-top-level-blocks-legacy.test-fixture.ts
  • src/renderer/src/components/sidebar/markdown-top-level-blocks.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nitpick comments: 1
src/renderer/src/components/sidebar/CommentMarkdown.parse-reuse.test.tsx: 1

211-225: Trivial · Maintainability & Code Quality · Quick win

Exercise the link-policy branch in this test.

The fixture contains no file-link candidate. The policy change therefore does not affect rendering. Add a supported candidate such as src/a.ts, then assert that the accepted link disappears when the callback rejects it.

Suggested fix
   const full =
-    'Intro\n\n  ```text\n  value\n  ```\n\n  - one\n\n        nested code\n\n  > quote\n '
+    'Edited src/a.ts.\n\nIntro\n\n  ```text\n  value\n  ```\n\n  - one\n\n        nested code\n\n  > quote\n '
...
     for (const content of sequence(full, 0)) {
       view.rerender(<CommentMarkdown content={content} math growing fileLinkExists={exists} />)
     }
+    const accepted = view.container.innerHTML
+    expect(view.container.querySelector('a')).not.toBeNull()
     view.rerender(<CommentMarkdown content={full} math growing fileLinkExists={() => false} />)
+    expect(view.container.innerHTML).not.toBe(accepted)
+    expect(view.container.querySelector('a')).toBeNull()
     snapshots.push(view.container.innerHTML)

Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 22c8aecf-10cf-47b8-8081-531d9c238576
Commits

Reviewing files that changed from the base of the PR and between 4044eae and 27ea22b.

Files selected for processing: 1
  • src/renderer/src/components/sidebar/CommentMarkdown.parse-reuse.test.tsx
Files skipped from review as they are similar to previous changes: 1
  • src/renderer/src/components/sidebar/CommentMarkdown.parse-reuse.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Long streaming replies could stutter because Markdown was parsed once to find block boundaries and again to render, and completed fences were rediscovered as following text arrived. This change reuses the pristine boundary parse for rendering and retains completed fences while the tail streams. Rendering, copy text, source lines, word fade and reveal behavior are preserved.

Full review complete on a0e0ac30c0cec288faba03f8c042212120287fb7, including the once-only main merge. Review found and repaired a visual-directive boundary regression: unsafe parser inputs now use the complete existing discovery step, while compatible unchanged blocks retain their identity. A three-seat architecture ruling and fresh correctness verification covered that repair. Independent final review found low merge risk and no negative user-facing trade-off. No open findings or deferrals.

Verified on this head:

  • 308 tests across 20 named files, including production-parser operation bounds at N and 10N, exact output, fallback transitions, iframe/fade identity, source positions and main’s file-link transform.
  • Seven real-scale benchmark workloads in four alternating baseline/branch orders; 3,430 exact-HTML comparisons passed. Every aggregate median and p95 improved. Completed fence plus streaming tail: median 12.56 → 0.73 ms, p95 18.21 → 1.60 ms. The PR body has the complete measurements.
  • CI passed, including static analysis/typecheck, all five test shards and macOS/Windows packaging. Whole-mechanism reference comparison, performance pass and readiness checklist passed. The outdated braces thread is addressed and resolved.

Performance is the tests row of the QA table: no app QA or screenshot is required because this change preserves appearance and changes no lifecycle flow. Timings measure synchronous renderer work and DOM commit in happy-dom; packaged frame rate, layout/paint, retained heap and other machines’ performance were not measured.

For Brennan’s review

@brennanb2025
brennanb2025 enabled auto-merge (squash) October 28, 2026 19:56
@brennanb2025
brennanb2025 disabled auto-merge October 28, 2026 19:56
@brennanb2025
brennanb2025 merged commit 30bb30e into main Oct 28, 2026
34 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.

1 participant