Repository navigation
perf(tooling): reuse directory entry types in source scans - #20212
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughThe source tree walker now uses Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to The traversal optimization preserves existing scan behavior, and no actionable merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 58c1d4d0-3820-41a7-9632-e4b59a685c19
📒 Files selected for processing (3)
config/scripts/source-tree-walk-benchmark.mjssrc/shared/source-scan/source-tree-scan.tssrc/shared/source-scan/source-tree-walk.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Directory entry types reused in the shared walker —
scanSourceTreenow iteratesreaddirSync(..., { withFileTypes: true })and takes the type from theDirent, keepingstatSynconly for symbolic links (including the broken-linkENOENT). Filters, extension/test exclusions, relative-path normalization, and link traversal are unchanged.src/shared/source-scan/source-tree-scan.ts:49 - Traversal operation-count tests — real-filesystem fixtures assert ordinary entries incur no
statSync, exclusions/options are preserved, directory links still stat exactly once, and broken links still throw.src/shared/source-scan/source-tree-walk.test.ts - Benchmark harness — counterbalanced
before/afterwalker benchmark that compares full results and re-verifies an ordered path/content fingerprint on every sampled walk.config/scripts/source-tree-walk-benchmark.mjs
I verified the behavior-preservation claim at the Node/libuv boundary rather than by inspection alone: Windows junctions are classified UV_DIRENT_LINK (so isSymbolicLink() is true and the ternary still calls statSync), regular directories are UV_DIRENT_DIR, and readdirSync({ withFileTypes: true }) resolves UV_DIRENT_UNKNOWN through an internal lstat (DirentFromStats), so the all-is*()-false state is unreachable through the public API. The new operation-count tests fail against the baseline walker, confirming they pin real behavior. Locally the new suite (5 tests) and the direct consumer config/scripts/win32-test-lane-registration.test.mjs (31 tests) pass, and oxlint is clean on the three changed files.
openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
|
Checked the unknown- An unknown directory from the filesystem therefore does not reach this walker with all type predicates false. A manually constructed/mock unknown |
…still walked
`readdirSync(..., { withFileTypes: true })` can hand back a Dirent whose
type the filesystem did not report. For that entry every predicate is
false, so the readdir-type fast path treated a real directory as a file
and silently dropped its subtree from every ratchet guard. Fall back to
`statSync` whenever the entry is neither conclusively a file nor a
directory, keeping the no-stat fast path for ordinary entries.
Also make the two readdir-order assertions in the walk test
order-independent; `scanSourceTree` returns raw readdir order, which
differs on tmpfs.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
DT_UNKNOWNentries are statted instead of being silently dropped —scanSourceTreenow treats aDirentwhose predicates are all false as needingstatSync, so a real directory the OS did not type is still walked. Symlinks keep their stat-follow; ordinary files/directories still skip it, so the perf win is preserved.src/shared/source-scan/source-tree-scan.ts:58- Regression test for the untyped-entry path — a mocked all-false
Direntfor a nested directory asserts the subtree is visited and exactly that entry is statted.src/shared/source-scan/source-tree-walk.test.ts:113 - Filesystem-order-independent inventory assertions — the nested-file and test/extension expectations switched to
arrayContaining/.sort(), since tmpfs readdir order differs from APFS/ext4. This keeps the same coverage (length + exact element set) without pinning an incidental order.src/shared/source-scan/source-tree-walk.test.ts:53
This addresses the DT_UNKNOWN concern CodeRabbit raised on the first revision. Verified locally on Linux/Node 24.19: the suite passes (6 tests), oxlint is clean on the three changed files, and the new test fails against the pre-fix walker (which dropped the subtree), so it genuinely pins the fix. The mocked readdirSync reset restores the real implementation, so the remaining cases still traverse the real filesystem.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
The fabricated-Dirent readdir mock could not satisfy both gates at once: vi.mocked(readdirSync) resolves to Node's Dirent<NonSharedBuffer> overload, so the mock needed a type assertion, and #19462's casting gate rejects new ones on changed lines. Removing the cast then failed tsc. Extract directoryEntryNeedsStat and test it directly with a structural probe. No mock, no cast, no top-level await, and the DT_UNKNOWN case is pinned: removing the fallback fails 'stats an entry whose type readdir could not report'.
|
Unblocked. The blocker was never the production fix — it was that the regression test could not satisfy two CI gates at once. The test fabricated a Fixed by extracting the decision into
The production behaviour is unchanged from the previous push — ordinary files and directories still take the no-stat fast path, so the PR's win is intact; only links and DT_UNKNOWN entries pay a |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Stat predicate extracted into
directoryEntryNeedsStat— the inlineneedsStatexpression moved to an exported helper with a structuralDirentTypeProbeparameter; thescanSourceTreecall site is unchanged, so there is no behavioral change.src/shared/source-scan/source-tree-scan.ts:44 DT_UNKNOWNcoverage moved to unit tests — the mocked-readdirSyncintegration test was replaced with three focused unit tests assertingfalsefor typed files/dirs,truefor links, andtruefor the all-predicates-false (DT_UNKNOWN) case. The predicate that the fix hinges on is still pinned.src/shared/source-scan/source-tree-walk.test.ts:123- Dead import removed — the now-unused
actualFsactual-module handle is gone;Fsis still used by theimportOriginaltype argument.
Verified locally: the suite passes (8 tests) and oxlint is clean on the three changed files.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
Repository checks were asking the filesystem for each file's type separately. Directory listings already supply that information, so use it and keep the extra lookup only for symbolic links.
What Changed
Use
readdirSync(..., { withFileTypes: true })in the existingscanSourceTreewalker. Preserve directory traversal, ignored names, test/extension filtering, lexical paths, and symlink handling. Symbolic links still go throughstatSync, including its error for broken links.Why
Several repository-wide safety checks share this walker. Each walk previously called
statSyncfor every nonignored entry, including files it subsequently excluded.Measured the actual baseline and candidate functions over the current checkout, with eight counterbalanced pairs after warmup (macOS arm64, Node 26.6.0):
srcmobile/srccloud/appsThe main tree walk is about 11% faster. This improves development/CI scanning; it is not a claim about application latency. The benchmark compares complete results up front and verifies ordered path/content fingerprints after every measured walk. OS-specific directory-type fallback costs can differ.
Linked Issue
Refs #20206. Performance audit PR 2, independent of PR #20208.
Visual Proof
N/A — no application UI or interactions change.
Testing
ORCA_BACKGROUND_LAUNCH=1 pnpm tcpasses;pnpm tc:nodepasses after the test type-import cleanup.Reproduce from the repository root:
git show 20ab99506541:src/shared/source-scan/source-tree-scan.ts | node config/scripts/source-tree-walk-benchmark.mjsReview
No Git subprocess, remote execution, RPC, agent status, or workspace assumptions change. The walker continues to use Node path utilities and preserve normalized relative paths. Existing symlink traversal is retained rather than silently excluding linked source.
Agent skill upstream boundary
Checklist