You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bunx ccusage@latest opencode takes over two minutes on large OpenCode history (~3.6 GB, 87k messages) #1344
Speed up PricingMap::find() by adding a result cache so repeated lookups of the same model name skip expensive fuzzy matching. Also remove a redundant missing-pricing check in the OpenCode adapter.
Why?
bunx ccusage@latest opencode takes over two minutes on my machine.
Profiling showed that 91% of the time goes to PricingMap::find() — ~21 seconds for OpenCode alone, plus similar overhead from other agents.
My OpenCode SQLite database has ~87,000 messages and is 3.6 GB. Despite only 47 unique model names, each message independently repeats the full pricing lookup chain. 36% of lookups miss the exact HashMap and fall through to iterating all 2,200 pricing entries with substring matching — roughly 150 million string comparisons in total.
How? (optional)
Two changes:
Add a result cache to PricingMap::find() — A OnceLock<Mutex<FxHashMap<String, Option>>> caches lookup results by model name (including misses). With only 47 unique models, the expensive fallback scan would run at most 47 times instead of 67,000+. The cache is invalidated automatically whenever the pricing table is updated (load_json, apply_overrides, etc.), so it stays consistent.
Skip the redundant missing-pricing check in the OpenCode adapter — Both calculate_open_code_cost and missing_open_code_pricing independently iterate through the same model candidates. When cost calculation already found pricing, the second check can be skipped entirely.
The cache lives in the shared PricingMap layer, so all agent adapters (Claude Code, Codex, Amp, etc.) benefit from it transparently. Memory overhead is negligible (~5 KB for typical usage).
This issue was auto-closed. Issues from new contributors are auto-closed by default.
Maintainers review auto-closed issues and reopen worthwhile ones. Issues that do not meet the quality bar in CONTRIBUTING.md may not be reopened or receive a reply.
Keep the issue short, concrete, and written in your own voice.
If a maintainer replies lgtmi, your future issues will stay open. If a maintainer replies lgtm, your future issues and PRs will stay open.
Historical audit: this discussion was auto-closed by the legacy contributor gate. That closure did not assess technical importance.
Audit result: resolved. A later merged change or the current main implementation covers this request. This item is kept for history and does not need to be reopened.
Activity
pullfrog commentedon Jun 21, 2026
github-actions commentedon Jun 21, 2026
This issue was auto-closed. Issues from new contributors are auto-closed by default.
Maintainers review auto-closed issues and reopen worthwhile ones. Issues that do not meet the quality bar in CONTRIBUTING.md may not be reopened or receive a reply.
Keep the issue short, concrete, and written in your own voice.
If a maintainer replies
lgtmi, your future issues will stay open. If a maintainer replieslgtm, your future issues and PRs will stay open.See CONTRIBUTING.md.
ryoppippi commentedon Jun 21, 2026
@turtton could you send a pr?
Marrocco-Simone commentedon Jul 7, 2026
I get the same problem with just 600 megabytes of history.
with bun, ccusage installed globally:
with npx:
both with version @20.0.14
Measuring with Claude Code, which has a lot lot more data (around 6 gigabyte)
Tested on a MacBook M4 Pro
turtton commentedon Jul 9, 2026
Thank you for merging my changes!
Sorry about that — I didn't know that force pushing would prevent the PR from being reopened🙏
ryoppippi commentedon Aug 31, 2026
Historical audit: this discussion was auto-closed by the legacy contributor gate. That closure did not assess technical importance.
Audit result: resolved. A later merged change or the current
mainimplementation covers this request. This item is kept for history and does not need to be reopened.