Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(web): reuse completed Markdown prefixes while streaming #11193

Mergedjuliusmarmingemerged 3 commits intolegend-perf/timeline-updates fromrefs/pull/11193/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

Streaming a response reparses completed code fences on every chunk. Preserve the parsed prefix through a closed top-level fence and reparse the changing suffix, following the completed-block reuse in Legend Markdown.

The existing whole-document transforms, sanitization, source positions and rendering remain in use. Reference definitions, footnotes, CR/CRLF and BOM input fall back to a full parse. Plain prose, completed messages and custom syntax plugins use the existing path. The cache belongs to one streaming renderer.

Five alternating production-browser runs at 1440 × 1000, each with 20 warm-up updates and 120 measured updates:

Client update timeBase, including minimap changeThis layer
Median of run medians21.5 ms17.4 ms
Median of run p95s34.0 ms30.3 ms

The fixture contains 12 completed TypeScript fences of 30 lines plus growing prose. Every paired run improved; the median reduction is 19.1%. Both builds use the same browser process, origin, fixture and probe. These are synchronous client-update measurements, not provider throughput or user telemetry. Raw samples · Probe, comparison script and parity evidence.

82 focused tests and web typecheck pass. The external CommonMark corpus adds 17,426 full-tree comparisons, including source positions, across its 652 examples. Browser verification retained selected text, DOM identity and exactly the same scroll position through 40 updates. Targeted lint reports two warnings in unchanged code.

This affects streaming Markdown in web and Electron's shared web renderer. Mobile and file/diff viewers are unchanged. Local and remote clients use the same rendering path; no transport, provider or contract changes.

Before, desktop:

Before: completed code blocks at the reading position

After, desktop:

After: identical code layout at the same reading position

Before navigation and streaming, narrow viewport:

https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/cf9292628b42deda/parser-before-demo.webm

After navigation and streaming, narrow viewport:

https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/45f147cf61401e0c/parser-after-demo.webm

Recordings show visual states, not wall-clock speed: the recorder compresses dropped-frame intervals. The table uses separate, unrecorded timing runs; 0.8 seconds of recorder startup was trimmed. Only synthetic fixture data is included. Probes and evidence are not committed.

Integration follow-up: rebased on current main; the integrated stack passes 94 focused Markdown/highlighting tests and 159 timeline tests, plus web typecheck. The timing table remains pinned to the original measured builds.

Model: GPT-6. Harness: Codex.

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ℹ️ No successful main baseline artifact is available yet. This run establishes the initial measurement.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire—13.6 KiB—15.1 KiB✅
      CodexThread snapshot wire—7.0 KiB—7.3 KiB✅
      CodexLive turn WebSocket wire—6.5 KiB—7.8 KiB✅
      CodexLive turn WebSocket decoded—57.0 KiB—66.4 KiB✅
      CodexLive turn messages—8—21✅
      ClaudeTotal thread wire—13.6 KiB—15.1 KiB✅
      ClaudeThread snapshot wire—7.1 KiB—7.3 KiB✅
      ClaudeLive turn WebSocket wire—6.5 KiB—7.8 KiB✅
      ClaudeLive turn WebSocket decoded—57.8 KiB—66.4 KiB✅
      ClaudeLive turn messages—8—21✅

      Baseline: unavailable · PR result: a660ad9 · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 113.9 KiB
      • Claude decoded thread snapshot: 114.6 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    3. Bugbot is paused — on-demand spend limit reached

      Bugbot uses usage-based billing for this team and has hit its on-demand spend limit.

      A team admin can raise the spend limit in the Cursor dashboard, or wait for the next billing cycle to continue.

    4. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This PR introduces stateful AST caching, parser wrapping, position shifting, and automatic fallback decisions in the production streaming Markdown path. Focused parity tests reduce risk, but the new parsing strategy and automatic processing gate are substantial runtime changes.

      No code changes detected at a660ad9. Prior analysis still applies.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    5. github-actions[bot](GitHub profile, opens in a new tab) added labels📱 Native Change

    6. github-actions[bot](GitHub profile, opens in a new tab) removed labels📱 Native Change

    7. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review Change StackReview Change Stack

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration

      Configuration used: Path: .coderabbit.yaml

      Review profile: CHILL

      Plan: Team

      Run ID: c89c418c-586f-4eb9-8adf-91e9ddc98f7e

      📥 Commits

      Reviewing files that changed from the base of the PR and between 3b9cf6eec966edd86aee57fdd74e46923e4c68b4 and a660ad9413e5dedba3937696a88c9ea17cbcc37a.

      ⛔ Files ignored due to path filters (1)
      • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
      📒 Files selected for processing (4)
      • apps/web/package.json
      • apps/web/src/components/ChatMarkdown.tsx
      • apps/web/src/markdown-incremental.test.tsx
      • apps/web/src/markdown-incremental.ts

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


      📝 Walkthrough

      Walkthrough

      The web app adds an incremental Markdown parser for eligible streaming messages. It caches completed fenced-code prefixes, integrates the parser into ChatMarkdown, and adds tests for parsing equivalence and fallback cases.

      Changes

      Incremental Markdown streaming

      Layer / File(s)Summary
      Incremental parser and plugin
      apps/web/src/markdown-incremental.ts, apps/web/package.json
      Adds cached-prefix parsing, AST cloning, position shifting, full-parse fallbacks, and the exported incremental plugin. Adds required development dependencies.
      Streaming renderer integration
      apps/web/src/components/ChatMarkdown.tsx
      Enables incremental parsing during streaming when fenced code is present and no extra remark plugins are configured.
      Parser behavior validation
      apps/web/src/markdown-incremental.test.tsx
      Tests cached prefixes, streaming positions, line endings, definitions, edits, repeated renders, transformed nodes, and code-fence edge cases.

      Priority: ➖ Normal

      Estimated code review effort: 3 (Moderate) | ~25 minutes

      Change: Refactor

      Sequence Diagram(s)

      sequenceDiagram
        participant ChatMarkdown
        participant IncrementalMarkdownPlugin
        participant MarkdownParser
        ChatMarkdown->>IncrementalMarkdownPlugin: enable for eligible streaming text
        IncrementalMarkdownPlugin->>MarkdownParser: parse current Markdown document
        MarkdownParser-->>ChatMarkdown: return Markdown AST for rendering

      Suggested reviewers: t3dotgg

      Merge Risk: ⚪ Minimal · up to a660a

      No merge-blocking risk was identified.

      🚥 Pre-merge checks | ✅ 4 | ❌ 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 3 files. (1 skipped: 1…Write docstrings for the functions missing them to satisfy the coverage threshold.
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Title check✅ PassedThe title clearly and concisely describes the main change: reusing completed Markdown prefixes during streaming for web performance.
      Description check✅ PassedThe description explains what changed, why it changed, scope, performance results, testing, and UI verification. It includes screenshots and videos for the rendering changes. It does not use the templ…
      Full details: Docstring Coverage

      Explanation

      Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 3 files. (1 skipped: 1 unsupported.)

      • Fix all pre-merge checks with AI
      ✨ Finishing Touches 💡 1
      📝 Generate docstrings 💡
      • Create stacked PR
      • Commit on current branch
      🧪 Generate unit tests (beta)
      • Create PR with unit tests
      • Commit unit tests in branch `legend-perf/incremental-markdown`

      Comment `@coderabbitai help` to get the list of available commands.
    8. juliusmarminge merged thisa9dabbf

    9. juliusmarminge closed this

Sign in to join this conversation.