Skip to content

perf(usage): cache reports across launches - #2

Merged
murongg merged 2 commits into
mainfrom
fix/startup-report-cache
Aug 1, 2026
Merged

perf(usage): cache reports across launches#2
murongg merged 2 commits into
mainfrom
fix/startup-report-cache

Conversation

@murongg

@murongg murongg commented Aug 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • persist the last successful usage report in a versioned, disposable cache
  • restore matching reports on launch before applying the existing refresh-age policy
  • share in-flight loads by complete UsageRequest across current, comparison, budget, and model-catalog reports
  • make concurrent callers wait for the shared result instead of continuing into duplicate downstream scans
  • ignore mismatched or malformed snapshots safely

Why

TokPeek currently starts with an empty report and calls Tokscale again on every launch. Users with large local histories can therefore stare at an empty dashboard while the scan completes, even when the previous result is still usable.

This keeps the previous aggregate visible immediately and refreshes it in the background when it is stale. When the menu bar and dashboard request the same data concurrently, they now reuse one core task from start to finish. The first cold Tokscale scan is unchanged.

Validation

  • ./scripts/test.sh
    • Rust: 4 tests passed
    • Swift: 74 tests passed
    • Xcode Scheme: TEST SUCCEEDED
  • git diff --check passed

Risk

  • cache data is aggregate usage metadata only and stays in the user cache directory
  • the cache format is versioned and disposable; decode failures fall back to a normal scan
  • snapshots are restored only when the complete usage request matches
  • in-flight work is shared only for exactly matching requests; generation checks still prevent older requests from overwriting newer results

Related Issues

Refs #1

@murongg
murongg merged commit c16e491 into main Aug 1, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant