Skip to content

perf(repo-diff): draw plain diff rows through the pool's windowed path - #974

Merged
devswha merged 2 commits into
mainfrom
perf/repo-diff-windowed
Oct 13, 2026
Merged

devswha merged 2 commits into
mainfrom
perf/repo-diff-windowed

Conversation

@devswha

@devswha devswha commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Follow-up to #951.

Problem

A diff drawn without colors (past the highlight bound, or highlighting off) rebuilt every one of its rows on the main thread on each render: every scroll step, wrap, split or resize. On the 10 000-line diff from repo-diff-browser-qa, at a 4x CPU slowdown, each scroll step held the page 130-270 ms.

Root cause

RepoDiff passed disableWorkerPool={!colored} and wrapped only colored diffs in DiffWorkerPool. Without a pool, @pierre/diffs' DiffHunksRenderer takes its no-pool path: renderDiffWithHighlighter over the whole diff, re-run on every render because forcePlainText (a massive diff) re-renders unconditionally. With a pool it uses the manager's getPlainDiffAST(diff, startingLine, totalLines, ...), which builds only the rows in view. VirtualSource had the same problem, fixed in 867e802.

Change

  • RepoDiff always renders inside DiffWorkerPool and drops disableWorkerPool. Plain diffs never reach a worker: tokenizeMaxLength: 0 keeps them massive, so no highlight is queued.
  • Updated the pool comments in DiffWorkerPool.tsx and sourceTheme.ts.
  • Added changelog.d/repo-diff-windowed-plain-rows.md (Fixed).

Validation

Measured with a scratch Playwright script (not committed) on the 10 000-line plain diff, desktop 1440px, CDP Emulation.setCPUThrottlingRate 4. The numbers are the longest long task per step across 3 runs:

step before after
open 248-280 ms (4 tasks, 781-872 ms total) 82-91 ms (2-4 tasks, 163-295 ms total)
scroll to middle 174-272 ms 116-127 ms
scroll to end 132-185 ms 72-75 ms
small scroll steps (x5) 134-224 ms 57-98 ms
wrap on 117-169 ms 68-84 ms
split 143-228 ms 95-118 ms
fold context 317-325 ms 220-303 ms

The fold step still costs about the same. Most of it is trimPatchContext and re-parsing the patch on the page, which this change does not touch.

  • CI=1 bun run check run --build bun scripts/repo-diff-browser-qa.ts: passes (all widths and themes, remote, demo)
  • bun run check fast: passes

🤖 Generated with Claude Code

RepoDiff passed disableWorkerPool={!colored} and wrapped only colored
diffs in DiffWorkerPool. Without a pool, @pierre/diffs' DiffHunksRenderer
renders a plain (massive) diff by running renderDiffWithHighlighter over
the whole diff on the page, and again on every render pass, since
forcePlainText re-renders unconditionally. With a pool present it takes
the manager's getPlainDiffAST, which builds only the rows in the window.
Plain diffs never reach a worker: tokenizeMaxLength 0 keeps them massive,
so no highlight is queued. Same fix as 867e802 for VirtualSource.

Measured on the 10 000-line diff of repo-diff-browser-qa, CPU throttled
4x, longest long task per step over three runs: open 248-280 ms -> 82-91
ms, each scroll step 132-272 ms -> 57-127 ms, wrap 117-169 -> 68-84 ms,
split 143-228 -> 95-118 ms.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 19 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: devswha/herdr-web-ui/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: dbea2feb-a31f-4314-8c8c-13cc4d0567d8
📥 Commits

Reviewing files that changed from the base of the PR and between ec0e5e7 and 123d889.

📒 Files selected for processing: 4
  • changelog.d/repo-diff-windowed-plain-rows.md
  • src/components/DiffWorkerPool.tsx
  • src/components/RepoDiff.tsx
  • src/lib/sourceTheme.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: devswha/herdr-web-ui/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e23e1ed9-64bd-43c8-b203-de2ed2e10f87
📥 Commits

Reviewing files that changed from the base of the PR and between 9dce921 and ec0e5e7.

📒 Files selected for processing (4)
  • changelog.d/repo-diff-windowed-plain-rows.md
  • src/components/DiffWorkerPool.tsx
  • src/components/RepoDiff.tsx
  • src/lib/sourceTheme.ts

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

📝 Summary

Summary by CodeRabbit

  • Performance Improvements
    • Long, unhighlighted diffs now render only visible rows, reducing unnecessary redraws while scrolling.

RepoDiff now routes plain diffs through DiffWorkerPool, where the pool manager windows rows. Comments and a changelog entry describe this behavior.

Changes: Plain diff windowing

Layer / File(s) Summary
Route diffs through the worker pool
src/components/RepoDiff.tsx, src/components/DiffWorkerPool.tsx, src/lib/sourceTheme.ts, changelog.d/repo-diff-windowed-plain-rows.md
RepoDiff now wraps both plain and colored diffs in DiffWorkerPool. Comments describe pool windowing and lifecycle. The changelog states that long plain diffs build only visible rows.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to ec0e5

Plain diffs remain windowed rather than rendering every row, so the suspected scrolling regression is not present. No actionable merge risk is established.

Pre-merge checks: Passed 5
Passed Passed checks (5 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: routing plain diff rows through the windowed worker-pool path.
Description check Passed The description explains the problem, root cause, implementation, resulting behavior, and validation results. It includes the required Change and Validation sections and provides relevant performance …
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 3 files. (1 skipped: 1 …
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.
✨ Finishing Touches 💡 1
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • 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.

@devswha
devswha merged commit c3c3314 into main Oct 13, 2026
15 of 17 checks passed
@devswha
devswha deleted the perf/repo-diff-windowed branch October 13, 2026 19:53
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