Skip to content

fix(session-ui): render large diffs as plain text in the worker pool - #46772

Merged
Hona merged 1 commit into
anomalyco:v2from
Hona:large-diff-plain
Sep 2, 2026
Merged

Hona merged 1 commit into
anomalyco:v2from
Hona:large-diff-plain

Conversation

@Hona

@Hona Hona commented Sep 2, 2026

Copy link
Copy Markdown
Member

DiffViewer asks for a plain-text fallback above 500 KB (largeOptions: lineDiffType: "none", maxLineDiffLength: 0, tokenizeMaxLineLength: 1), but Pierre's DiffHunksRenderer.getRenderOptions uses the worker pool's render options whenever the pool works. The dedicated "none" pool only carried lineDiffType, so every >500 KB diff was still fully Shiki-tokenized (1000-char line cap) on each mount, about 6 s in the worker for a 625 KB patch.

  • The "none" pool now carries the plain-text options the viewer requests. It only serves diffs above the large-file threshold (file.tsx picks it via large()), so ordinary diffs keep word-alt intra-line diffs and full highlighting on the default pool.
  • Large diffs render as plain text through the same worker path, with complete content, hunks, and line numbers intact. largeOptions in file.tsx stays as the no-pool fallback.
// packages/session-ui/src/pierre/worker.ts
{
  theme: "OpenCode",
  lineDiffType,
  ...(lineDiffType === "none" && { maxLineDiffLength: 0, tokenizeMaxLineLength: 1 }),
  preferredHighlighter: "shiki-wasm",
}

Benchmark

packages/session-ui/performance/highlighting: production File (diff mode, virtualized), normalize, getWorkerPool, bundled Pierre worker. TypeScript route-handler file, one edited line per ten handlers. Each isolated page: cold mount, unmount and remount, then an edited patch. ready = production onRendered, pool idle, and the final worker result committed by onPostRender with the expected edit visible. Chromium 147 headless, 1280x800, 20 serial pages per case, medians (p95). Baseline 32d4375b39 (benchmark commits only) vs candidate 6e00f90629.

Case Phase ready ms before ready ms after worker ms before worker ms after syntax spans tokenizeMaxLineLength
1,200 fn / 625 KB patch / 15,599 lines cold 6580 (9545) 432 (506) 6330 195 730 → 0 1000 → 1
remount 6182 (8780) 178 (203) 6139 157 730 → 0 1000 → 1
changed 5971 (9063) 228 (266) 5859 150 730 → 0 1000 → 1
120 fn / 62 KB patch / 1,559 lines (unchanged path) cold 1060 (1371) 849 (931) 804 625 730 → 730 1000 → 1000
remount 632 (1115) 493 (570) 595 465 730 → 730 1000 → 1000
changed 592 (915) 514 (574) 537 470 730 → 730 1000 → 1000
  • The ordinary case uses the untouched word-alt pool; its deltas are run-to-run variance on a shared machine (the same shift appears in an unrelated candidate run), not an effect of this change.
  • Reconstructed before/after content is byte-equal to the inputs in every run. The correctness check asserts plain options and zero syntax spans for the large fixture and full highlighting for the ordinary fixture.
  • Visual change for >500 KB diffs only: plain text instead of syntax colors. This is the behavior file.tsx already intended.
Before (625 KB diff) After

@Hona
Hona marked this pull request as ready for review September 2, 2026 09:23
Copilot AI lite review requested due to automatic review settings September 2, 2026 09:23

Copilot AI 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.

🟢 Approval recommended

The change is narrowly scoped, aligns worker-pool behavior with the existing large-diff fallback intent, and includes a dedicated benchmark plus correctness validation.

Pull request overview

This PR fixes session diff rendering for large patches by ensuring Pierre’s "none" worker pool uses the same plain-text fallback render options that File already intends for diffs over ~500 KB, preventing expensive Shiki tokenization on every mount. It also adds a reproducible performance/correctness harness under packages/session-ui/performance/highlighting to benchmark and validate the behavior.

Changes:

  • Update the Pierre worker pool creation so the "none" pool applies { maxLineDiffLength: 0, tokenizeMaxLineLength: 1 } in addition to lineDiffType: "none".
  • Add a Vite + Playwright-based benchmark/correctness suite for diff highlighting performance and verification.
  • Add vite-plugin-solid to support the new benchmark build pipeline.
File summaries
File Description
packages/session-ui/src/pierre/worker.ts Ensures the "none" worker pool uses plain-text fallback render options for large diffs.
packages/session-ui/performance/highlighting/viewer.tsx Adds an in-browser production-fixture viewer to measure worker/render timings and verify output.
packages/session-ui/performance/highlighting/viewer.bench.ts Adds Playwright benchmark runner to collect timing stats and report them consistently.
packages/session-ui/performance/highlighting/plain.correctness.ts Adds correctness coverage for “large diff is plain text” while preserving ordinary highlighting.
packages/session-ui/performance/highlighting/playwright.config.ts Configures Playwright execution for bench vs correctness modes and local web server.
packages/session-ui/performance/highlighting/build.ts Adds Vite build script to generate an external artifact bundle and build metadata for comparisons.
packages/session-ui/performance/highlighting/serve.ts Adds a minimal Bun static server for serving the built benchmark bundle.
packages/session-ui/performance/highlighting/index.html Adds the benchmark entry HTML that loads the viewer module.
packages/session-ui/performance/highlighting/README.md Documents how to build and run the benchmark/correctness suite.
packages/session-ui/package.json Adds vite-plugin-solid to devDependencies for the benchmark build.
bun.lock Updates the lockfile to include vite-plugin-solid.
Review details
  • Files reviewed: 10/11 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Hona
Hona merged commit 6ea388a into anomalyco:v2 Sep 2, 2026
8 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