Repository navigation
perf(web): load the files the reader is looking at first - #1354
Conversation
A large browser review loaded every canonical file in catalog order and re-rendered the whole stream for each batch, so a file jumped to at the end of a 2,000-file review stayed "Loading…" for ~30 s. Free read slots now take a jump's target (agent navigate, deep link, go-to-file, sidebar), then the files near the viewport, then the rest in document order; wanted files are shown within a frame and background files are batched every 250 ms. Go-to-file and sidebar jumps to a file that has not loaded yet now wait for it instead of doing nothing, and a revealed file stays in place while files above it land. The stream no longer re-observes every section when a file lands, the mirror builds each snapshot once per notification instead of copying the slots per file, and an unmeasured resource is hashed once instead of twice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Nn5HpgDBQrjicbK5ZoZnMG
[Medium impact] The changes affect loading and navigation across browser-based reviews. Fix cancellation of waiting jumps before merging so Back cannot be undone by a file arriving later. Findings
Fix with agent prompt### Issue 1
packages/hunk/src/web/app/useReviewTools.tsx:273-277
Pick an unloaded file in go-to-file, then press Back before it arrives. `onPopState` calls `show` without clearing `pendingJump`, so this retry jumps to the abandoned file when it loads. The selection subscription also overwrites the current history entry with that file’s address.
Clear or replace the waiting jump when browser history moves, and test Back while the chosen file is still loading.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryThis PR loads jump targets and nearby files before background files.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Free read slot] --> B{Unread jump target?}
B -->|Yes| E[Read file]
B -->|No| C{Unread nearby file?}
C -->|Yes| E
C -->|No| D[Next file in document order]
D --> E
E --> F{File wanted now?}
F -->|Yes| G[Notify within a frame]
F -->|No| H[Batch background updates]
G --> I[Update review document]
H --> I
Reviews (1) · Last reviewed commit: "perf(web): load the files the reader is ..." · Reviewed by Greptile |
| const loaded = session.review.store | ||
| .getSnapshot() | ||
| .document.files.some((file) => file.key === address.fileKey); | ||
| if (loaded) { | ||
| showOrWait(address); |
There was a problem hiding this comment.
Back leaves waiting jumps active
Pick an unloaded file in go-to-file, then press Back before it arrives. onPopState calls show without clearing pendingJump, so this retry jumps to the abandoned file when it loads. The selection subscription also overwrites the current history entry with that file’s address.
Clear or replace the waiting jump when browser history moves, and test Back while the chosen file is still loading.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/hunk/src/web/app/useReviewTools.tsx
Line: 273-277
Comment:
**Back leaves waiting jumps active**
Pick an unloaded file in go-to-file, then press Back before it arrives. `onPopState` calls `show` without clearing `pendingJump`, so this retry jumps to the abandoned file when it loads. The selection subscription also overwrites the current history entry with that file’s address.
Clear or replace the waiting jump when browser history moves, and test Back while the chosen file is still loading.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Problem
The browser review loads a review's
canonical-fileresources in catalog order, 4 at a time, and every batch of landed files re-rendered the whole stream (all 2,000 sections, the sidebar, the minimap) and re-observed every section with a newIntersectionObserver. The main thread was saturated by rendering, so reads crawled: onmain, after jumping to the last file of a 2,000-file review (hunk session navigate <id> --file <last>), that file stayed "Loading…" for ~30 s, until everything else had loaded. A go-to-file or sidebar jump to a file that had not loaded yet silently did nothing.review-large.e2e.tshid this behind 120 s timeouts.Approach
mirror/fileLoadOrder.ts, new): each free read slot takes the next file from a live order: a jump's target still waiting for its file (agent navigate, deep link, go-to-file, sidebar), then the files the stream is about to draw (its mount window, 1.5 viewports), then the rest in document order. The page names them withClientReviewMirror.prioritize("target" | "viewport", keys); reads not started yet follow the new order, reads in flight finish.ReviewApiClient.readResourcestakes an optionalReviewResourceReadOrder(pull-based) instead of a fixed index walk. Concurrency is unchanged (the shared bound of 4), the supersede queue still cancels an older generation's load, and aborted reads are still dropped at the daemon.ResizeObserver(before paint) and keeps the selection until the reader's own wheel, touch, pointer, or key input, or a scroll command. After loading, behavior is as before.Non-goals: no change to the daemon/session side, the wire, or the shared read concurrency; no worker-based highlighting (Pierre already only mounts files near the viewport). Mirror-the-TUI does not apply (the terminal loads its document locally).
Measurements
Same machine (Linux, 4 vCPU, shared with other jobs, so absolute numbers moved between runs), Chromium headless 1280×720, production (minified) build of each tree. "Target rows" is from issuing the jump to the jumped-to file's diff rows existing in its shadow root (includes the
hunk session navigateCLI process, 0.4–1.6 s); "all loaded" is until the toolbar's load progress disappears; heap is CDPJSHeapUsedSizesampled every 200 ms (peak) and after a forced GC at the end.navigate --file <last>(3 runs)navigate --file <last>An earlier, quieter run on main measured 32.1 s / 32.2 s / 274 MB for the first row. The heap that remains after GC is the loaded document itself and is unchanged; the peak drop is garbage from the per-file re-renders. In this PR's runs the target file stayed selected and in view after everything finished loading.
Benchmark script (Playwright, uses the repo's web test harness)
Save as
bench/load.bench.tsnext tobench/playwright.config.ts(testDir: ".",testMatch: "**/*.bench.ts",workers: 1,timeout: 900_000,use: devices["Desktop Chrome"]), symlinkbench/node_modulesto the checkout'snode_modules,bun run build:webin the checkout, then:The patch was generated with 1,688 modified
.tsfiles of 4 hunks × (3 context + 45 removed + 45 added + 3 context) lines each (≈48 MB). Note: a 41 MB patch shaped as 12 hunks × 10 lines per file never registered with the daemon (the page waited for the publication). I saw it on this branch, whose session side is identical to main; it looks like a separate session-side limit and is not touched here.Tests and checks
bun run typecheck,bun run lint,bun run format:check,bun run deps:check: pass.bun test packages/hunk/src/web test/review-conformance scripts/quality/source-boundaries.test.ts: 535 pass. New:fileLoadOrder.test.ts(target, viewport, background order; live reprioritization; each file once), a mirror test (target and viewport files land first and notify on a frame, the rest batched), and anapiClienttest (reads follow a caller's order).bun run build:web && npx playwright test --config test/web/playwright.config.ts --trace off test/web/review-large.e2e.ts test/web/review-stream.e2e.ts test/web/review-stream-measurement.e2e.ts test/web/review-keyboard.e2e.ts test/web/review-palette.e2e.ts test/web/review-notes.e2e.ts test/web/review-shell.e2e.ts test/web/review-sidebar.e2e.ts test/web/review-interactive.e2e.ts: all pass (73 tests).review-large.e2e.tsis tightened: right after the file count shows, a go-to-file jump to file 1000 and thenhunk session navigateto file 1999 must each be selected and draw diff rows within 15 s (previously ~30 s on an idle machine, so this keeps headroom for a loaded runner and still fails on the old ordering); the whole load must finish within 90 s (was 120 s), and the navigated file must still be selected and in view afterwards. Run againstmain, the new test fails at the go-to-file step (the jump is ignored), and with that step removed it fails at the navigate step (15 s timeout).Platforms: Linux only (Chromium headless). Not tested on macOS or Windows.
Repro
Known limitations
scrollTopdirectly during the first load does not release it until loading ends.https://claude.ai/code/session_01Nn5HpgDBQrjicbK5ZoZnMG
Generated by Claude Code