perf(dashboard): cache the derived payload so agent toggles stop rebuilding it - #12
Merged
Merged
Conversation
…ilding it
Switching the agent tab re-derived the whole page from the same transcripts:
4.0s for Claude, 1.3s for All Agents, every single toggle. Nothing about that
work depends on which tab was clicked last, so it is now memoised.
insights.build splits into _build_payload — the transcript-derived half — and a
thin wrapper that caches it under (range, agent, transcript fingerprint, store,
capture). The fingerprint comes from sessions(), so appending a turn retires
every entry derived from the older transcripts and a stale payload cannot
outlive its data. The live telemetry counters stay outside the cached dict and
are re-read per request; they move on each proxied turn rather than when a
transcript is written, and caching them would freeze the one number on the page
meant to be live. The cache is bounded, since entries keyed on a retired
fingerprint are dead weight.
Two scans behind it were also repeating work:
* sessions() rebuilt its fingerprint by walking and stat-ing every transcript
on cache hits as much as misses (~0.35s). A short freshness window lets a
burst of toggles reuse it, well under the time it takes to notice a missing
turn.
* skill_miner._scan_transcript_logs parses every line of every transcript —
179k json.loads here — and ignores the sessions it is handed, so it returned
an identical answer for each tab and was rerun for each. Memoised on the
same fingerprint shape.
Measured over HTTP against a real transcript directory: a repeat toggle goes
from 4.0s to 1.2ms, and a first visit to the Antigravity tab from 1.45s to
0.35s. The suite gained seven tests and still got faster, 11.9s to 10.2s.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Description
Switching the agent tab re-derived the whole page from the same transcripts: 4.0s for Claude, 1.3s for All Agents, every single toggle. Nothing about that work depends on which tab was clicked last, so it is now memoised.
insights.build splits into _build_payload — the transcript-derived half — and a thin wrapper that caches it under (range, agent, transcript fingerprint, store, capture). The fingerprint comes from sessions(), so appending a turn retires every entry derived from the older transcripts and a stale payload cannot outlive its data. The live telemetry counters stay outside the cached dict and are re-read per request; they move on each proxied turn rather than when a transcript is written, and caching them would freeze the one number on the page meant to be live. The cache is bounded, since entries keyed on a retired fingerprint are dead weight.
Two scans behind it were also repeating work:
Measured over HTTP against a real transcript directory: a repeat toggle goes from 4.0s to 1.2ms, and a first visit to the Antigravity tab from 1.45s to 0.35s. The suite gained seven tests and still got faster, 11.9s to 10.2s.
Type of Change
Verification
Describe the tests and checks performed to verify changes:
pytestpasses cleanly.python -m buildandtwine check dist/*pass.scripts/e2e_test.pypasses.Checklist
CHANGELOG.mdwith my changes.