Repository navigation
perf(watch): read directory names synchronously in bounded batches - #747
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 28, 2026, 2:12 AM ET / 06:12 UTC (Revision 3). ClawSweeper reviewWhat this changesThe branch makes Node.js watch scans read directory names synchronously with periodic yields, and adds regression tests, a benchmark, documentation, and broader watch CI coverage. Merge readiness⛔ Blocked before merge - 4 items remain Keep open: this is a distinct, well-supported watch performance improvement absent from current main and the latest release. It merits maintainer review. Priority: P2 Review scores
Verification
How this fits togetherThe watch API takes an admitted filesystem Root and selected paths, then scans directory names and metadata behind identity checks to produce advisory invalidations. This change affects name reads during Node.js watch scans. flowchart LR
A[Admitted Root and scopes] --> B[Watch scan]
B --> C[Guarded directory listing]
C --> D{Runtime}
D -->|Node.js| E[Bounded synchronous name reads]
D -->|Bun or Deno| F[Asynchronous name reads]
E --> G[Identity and budget checks]
F --> G
G --> H[Watch snapshot and invalidations]
Decision needed
Why: The benchmark establishes a substantial warm-cache gain, but setting an acceptable stall limit for other application work requires watch-owner judgment. Before merge
Findings
Agent review detailsSecurityNone. Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the watch-only Node.js optimization and its identity fences, record the measured gain for users, and establish an acceptable event-loop delay bound for slow storage. Do we have a high-confidence way to reproduce the issue? Not applicable as a functional bug; the PR supplies a repeatable public watch benchmark and baseline-to-candidate timing results for the performance claim. Is this the best way to solve the issue? Yes for the measured Node.js hot path: the change is isolated to watch scans and retains the existing guards. Its slow-storage latency tradeoff still needs a bound or explicit acceptance. Full review comments:
Overall correctness: patch is correct AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against a3ccbc4cc2c6. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (2 earlier review cycles) |
Node watch scans spend about a second of a 50,000-file scan awaiting one-entry directory reads. Read those names synchronously with the existing one-entry buffer and yield every 32 reads. Keep every pre-read, post-read/pre-stat, and post-stat identity fence, exact identity handling, budget lookahead, and no-follow metadata observation. Bun and Deno retain asynchronous reads because bounded synchronous buffering is not established there.
Only
openRootDirectoryListing({ exactIdentity: true })selects this path. Its only production caller issrc/watch-scan.ts; Root.list/walk, locks, JSON-store, and all other method benchmark rows cannot execute it. New regression tests cover runtime routing, budget lookahead, cancellation, and a directory swap between name read and leaf metadata. Native CI now runs all watch suites, and the stress workflow also runs 500 model seeds per mode and soak-short.Accepted performance study
Dedicated AWS Crabbox
cbx_dd3910954cd8(released): c7a.8xlarge / AMD EPYC 9R14, Linux x64, Node v24.18.1, pnpm 12.4.2, Rust 1.98.1. Warm tmpfs fixture: 2,000 child directories × 25 files; the root adds one directory. This is metadata-cache performance, not cold-storage performance.Frozen measured base:
25de32860e5f73dd2ba7aeeb9078197a22d5df96. This PR was applied to fresh main85474b5e9cb57243e59f11fa614cc7971998b6c8; the watch scanner, listing helper, and directory guards are unchanged between those bases. The committed benchmark is byte-identical to the measured harness (SHA-256d18eea480e79fd7d73153913de7915e7c37f0b2d8859af0fd98e2ec6155a112b). Both artifacts used native addon SHA-2568e40530c1146079cd8285f64e9847f80b99eb6863df2a856086ded47b688843d.Each transport uses one process, both distributions, and one unchanged fixture: public
ready, then publicreconcile(), with Root construction and close outside timing. One warmup per arm; five ABBA and five BAAB blocks, ten samples per arm per order (twenty pooled). The A/A control uses the identical baseline artifact. No samples discarded. The 95% intervals are paired-block bootstrap intervals (10,000 draws, fixed seed, stratified by order); control spread is the full range of paired-block percentage deltas.All targeted medians improve by more than 10% and twice the A/A spread, in both run orders.
strace -c -fincludes startup, ready, one reconcile, and shutdown, with fixture construction outside tracing. Traced wall times are not acceptance timings. Expected readlink EINVAL probes come from realpath.Full-method controls and scope
The unfiltered
pnpm benchmark:methodssuite ran before/after in both off and require modes, with 20 iterations, 10 samples, and one warmup: 994 measured off rows and 1,013 require rows. Harness SHA-256:00a6edc40be6183253e778874fd517574ee264e0b3e59a99efd50beba404107c.The broad sweeps flagged unrelated rows, but an identical-baseline rerun reproduced large drift: lock verification 562.28 → 983.52 µs (+74.92%); JSON-store read 445.82 → 666.04 µs (+49.40%). Those rows cannot reach the changed exactIdentity branch. The coordinator accepted this scope argument and environmental A/A evidence together with the reproducible targeted result and unchanged metadata syscall counts. These noisy rows are not claimed as measured improvements.
Reproduction
Build baseline and candidate separately, preserve each matching dist/native package layout, then run the same harness against both:
node scripts/watch-scan-benchmark.mjs setup /tmp/watch-perf-10k 400 node scripts/watch-scan-benchmark.mjs setup /tmp/watch-perf-50k 2000 node scripts/watch-scan-benchmark.mjs compare /tmp/watch-perf-50k 2000 /baseline/dist /candidate/dist node scripts/watch-scan-benchmark.mjs compare /tmp/watch-perf-50k 2000 /baseline/dist /baseline/dist strace -c -f -o counts.txt node scripts/watch-scan-benchmark.mjs once /tmp/watch-perf-50k 2000 /candidate/dist /candidate/dist poll # Repeat traced once for events and both distributions, at both fixture sizes. pnpm benchmark:methods --mode off --iterations 20 --samples 10 --warmup 1 --json methods-off.json pnpm benchmark:methods --mode require --iterations 20 --samples 10 --warmup 1 --json methods-require.jsonValidation
Fresh-head AWS proof used dedicated lease
cbx_8215ceae7292(released), runrun_a253898cee60e802d83ce03a1d890ccb, at headcd485adc492f47bb8240342ce8ad5368eaecc7ad:pnpm check: 16,595 passed, 682 expected skips; file-size and filesystem-boundary lint, build, WASM allocator tests, docs, and installed-package checks passed.git diff --checkpassed. Scoped Codex autoreview was clean at P0–P2. The prior Bun eager-enumeration finding was fixed before this patch was accepted.Exact-head CI and watch stress both passed on attempt 1 at
cd485adc492f47bb8240342ce8ad5368eaecc7ad. The stress artifacts verify churn, lifecycle, soak-short, 500 model seeds per mode, and every other dispatched scenario on Linux x64/arm64, macOS arm64/Intel, and Windows x64. The native CI watch suites also passed, including musl and Windows Server 2022. All PR checks are successful or intentionally skipped. No macOS or Windows speedup is claimed. Do not merge as part of this performance study.