Repository navigation
perf: single-pass parse for dashboard ranges + correlation scan hoists - #1108
Merged
Merged
Conversation
…lation loops
renderDashboard issued three parseAllSessions calls (scan range, plan window,
durable headline). They often share a START and differ only in where they end —
end-of-day vs each caller's own `new Date()` — which the exact-key memo cannot
match, so a warm render paid for the discovery sweep, the cache read and the
parse two or three times over.
withSinglePassParse lets a caller declare the widest range it will ask for. A
later request that is a PURE NARROWING of it is served by slicing that parse
instead of running the pipeline again. Pure narrowing is deliberately strict:
same start, an end that is inside, and the same month shard scope. Both extra
conditions are load-bearing, because a parse's file set is a function of its
range:
- a changed file with `mtimeMs < range.start` is skipped without being parsed,
so an earlier start reads files a later start never sees;
- loadCache reads only the shards monthScopeForRange selects;
- either way the extra files seed seenKeys/seenMsgIds BEFORE the range slice,
and a seeded key suppresses the matching in-range turn in a provider parsed
later — usage the narrower parse would have counted.
Holding start and month scope equal makes both parses see an identical file set,
leaving the range slice as the only difference — the same trade burstReuse
already makes for the mirror-image case (same start, later end).
Independently, correlateCrossProviderPrSessions ran two O(n*m) scans: a
`sessions.filter` per subagent child (now a one-shot agentId index) and a full
`launches.filter` per candidate (now a sorted array plus a windowed scan). Both
preserve the exact match set; launch order was never observable because the
matches collapse into a Map keyed by the sorted ref list.
Warm, 21k-file corpus, isolated cache, median of 5 interleaved:
today 5.12s -> 3.81s (1.34x) 3 parses -> 2
month 5.46s -> 3.41s (1.60x) 2 parses -> 1
today --format json 4.11s -> 3.49s (1.18x, correlation hoist only)
vitest.config gains an explicit exclude so a .claude worktree's stale tests/
copy stops being swept into the run.
Refs #1106
This was referenced Aug 23, 2026
Merged
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 #1106. Stacked on #1105 (base branch =
perf/1104-discovery-sweep; retarget to master after #1105 merges).What
renderDashboardissued threeparseAllSessionscalls (scan, plan usages, durable overview) whose ranges differ only in their ends (~1s apart) — the exact-key memo never hit.withSinglePassParse(range, fn): the dashboard declares its widest range; any request inside the callback that is a pure narrowing — same start, end ≤, same month-shard scope — is served by slicing the one parse.month: 2 parses → 1.today: 3 → 2 (plan window starts on the 1st, scan at midnight — different starts cannot merge under the provable rule).correlateCrossProviderPrSessions: per-childsessions.filter→ one-shot agentId index; per-candidatelaunches.filter→ sorted array + windowed scan. Match sets identical.vitest.config.ts: exclude.claude/worktrees/**(stale agent worktrees were swept intonpm test).Why not full containment reuse (the sub-second lever)
Deliberately NOT shipped: a parse's file set depends on its range via two mechanisms — the
fp.mtimeMs < dateRange.startskip andmonthScopeForRangeshard selection. A wider parse reads files a narrower one never sees, andseenKeys/seenMsgIdsseed beforeturnSlicedToRange— so a wider parse can dedup-drop an in-range turn a narrower parse counts. That's a loss, not an attribution shift; it's the same reasonburstReusepinsstartMs. (Empirically: 6mo-parse-then-slice was byte-identical to a direct today-parse on this corpus — promising but unproven; left as a candidate on the issue.)Parity (frozen APFS-clone corpus, isolated caches, vs #1105 base)
Byte-identical except
/generated: warmtoday/month/models/all/sessions/statusJSON; cold same set + per-provider; rendered TUI stdout fortodayandmonth; and a 16-case harness over the three dashboard-derived numbers (period × provider × scrollable-history) — 16/16 identical incl. carriedCostUSD and per-session attribution. (Run under TZ=Etc/GMT+12 to keep 'today' non-empty against the frozen corpus.)Perf (isolated, median of 5 interleaved)
today(TUI)month(TUI)today --format jsonLive-corpus spot check: warm
today~3.97s (was 9.3s on main before #1105+#1106).Tests
New
tests/single-pass-parse.test.ts(5, spy-counted parses — non-vacuous): slice-vs-direct equality, boundary straddling, start mismatch re-parses, month-scope mismatch re-parses, no scope leak. Full suite green (232 files / 3182 tests). No cache version, payload, or dep changes.