Repository navigation
perf: fan out the discovery sweep instead of walking it one syscall at a time - #1105
Merged
Merged
Conversation
…t a time Every dated command re-walks and re-stats every provider tree before it can decide what the cache already covers. That sweep was strictly serial at every level -- one readdir, one stat, one state.json read at a time, and one provider after another -- so on a 21k-file / 9-provider corpus it owned most of a warm run's wall clock with the machine idle waiting on the kernel. Measured per warm `today` pass on that corpus before this change: 859 ms in discoverAllSessions (kimicode 467, codex 143, claude 135, grok 77) and 727 ms in the Claude project walk + fingerprint pass. - fs-utils: mapWithConcurrency + FS_SCAN_CONCURRENCY, one bounded, order- preserving helper for the whole sweep. - providers/index: run provider discovery concurrently, concatenated in registry order. - claude/codex/grok/kimicode: walk each level with the level fanned out, re-concatenated in readdir order before anything reconciles. - parser: the Claude dir walk and both fingerprint passes (scanProjectDirs and parseProviderSources) fan out, then reconcile serially in discovery order, which is what changedFiles ordering and the seenMsgIds pre-seed depend on. - parser: collectJsonlFiles reads entries with their types, so a plain file no longer costs a wasted subagents/ probe. - codex-cache: share one in-flight load between concurrent readers. The memo is only populated after the read + parse resolves, so concurrent discovery had every caller re-reading and re-parsing the same (here 59 MB) file. No reconciliation logic changed: the same fingerprints reach the same cache comparison in the same order. Warm `today` 5.30s -> 2.99s, cold 34.7s -> 31.1s (medians of 5 / 2, isolated HOME + cache). today/report -p month/models/sessions JSON, warm and cold, per-provider and combined, are byte-identical apart from the run's own `generated` timestamp. Closes #1104
This was referenced Aug 22, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1104 (partially — see honest scope note at the end).
What
The discovery sweep was syscall-serial: one
readdir/statat a time across ~21k files, leaving the OS idle between calls. This PR overlaps the metadata syscalls (bounded, concurrency 32) while keeping every order-sensitive reconcile loop serial and in discovery order.fs-utils:mapWithConcurrency— order-preserving bounded poolproviders/index: providers discover concurrently, concatenated in registry orderkimicode/codex/grok/claude: nested serial walks → level-by-level fan-out (kimicode was the single biggest term)parser.tsscanProjectDirs/parseProviderSources: walk+fingerprint fan out, reconcile stays serial (changedFiles order drives worker-result pairing and seenMsgIds pre-seeding)collectJsonlFiles: typed readdir; plain files no longer cost a wastedsubagents/probe (isFile()deliberately, so symlinked dirs are still probed — test covers it)codex-cache: latent bug exposed by the fan-out —loadCachememoized only after resolve, so 32 concurrent callers each re-read + re-parsed the 59MB results file (first attempt regressed 6.3s→11.0s). Fixed by sharing the in-flight promise.Never-lose
No change signal was touched: fingerprints are still
(dev, ino, mtimeMs, size)from one stat,reconcileFileunchanged. No early-exit removed, no writes parallelized, no cache version bump, no payload shape moved. Discovery order preserved everywhere via index-addressed results.Parity
APFS-cloned all provider roots into a frozen HOME + isolated cache; ran main vs branch:
today,report -p month,models— identical except/generated(run's own timestamp)report -p all,models,sessions, per-providerreport -p all --provider {codex,kimicode,grok,claude}— all identical except/generatedPerf (21k files / 9 providers)
today(isolated, median of 5)sys time −31%. Interleaved A/B runs confirm the gap is the build, not drift.
Tests
tests/discovery-concurrency.test.ts(7) +tests/codex-cache-concurrent-load.test.ts(1, verified non-vacuous). Full suite: 231 files / 3177 tests green.Scope note
This is 1.77x, not the 'low hundreds of ms' prize. Post-change profile: the sweep is now 570ms/pass but
renderDashboardruns the whole pipeline three times (three range-distinctparseAllSessions, no shared memo), and the non-sweep floor (correlateCrossProviderPrSessions270ms/pass,loadCache190ms/pass, parse/summarize) × 3 ≈ 2.6s that no discovery work can touch. Follow-up issue incoming for the 3× pipeline collapse — that's the next real lever.