Repository navigation
perf(rust): move pricing snapshots into a leaf crate - #1922
Conversation
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
⛔ Files ignored due to path filters: 1
📒 Files selected for processing: 37
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
ccusage-guide | a36c243 | Commit Preview URL Branch Preview URL |
Oct 18 2026, 03:26 PM |
ccusage
@ccusage/ccusage-darwin-arm64
@ccusage/ccusage-darwin-x64
@ccusage/ccusage-linux-arm64
@ccusage/ccusage-linux-x64
@ccusage/ccusage-win32-x64
commit: |
ccusage performance comparisonPR SHA: Performance comparison skipped. Base package URL was not ready before 300.000s. Fixture performance comparison requires a base package when --base-dir is not provided. Base package: |
ccusage performance comparisonPR SHA: Performance comparison skipped. Base package URL was not ready before 300.000s. Fixture performance comparison requires a base package when --base-dir is not provided. Base package: |
ccusage performance comparisonPR SHA: Performance comparison skipped. Base package URL was not ready before 300.000s. Fixture performance comparison requires a base package when --base-dir is not provided. Base package: |
ccusage performance comparisonPR SHA: Performance comparison skipped. Base package URL was not ready before 300.000s. Fixture performance comparison requires a base package when --base-dir is not provided. Base package: |
Most commits on main are the scheduled "chore(pricing)" snapshot updates, and each one invalidated the foundation and adapters Crane layers: ccusage-core embedded the models.dev JSON through its build script, and CCUSAGE_PRICING_JSON_PATH (the litellm flake input) was passed to every layer. A models.dev or LiteLLM bump therefore rebuilt ccusage-core, every adapter, the config-schema generator, and the clippy, hawk and test bases. The snapshot build script and the committed models.dev files now live in ccusage-pricing-snapshots, a dependency-free crate only the binary links. ccusage-core keeps the loaders and receives the deflated bytes through pricing::set_embedded_snapshots, installed in main() next to the existing set_json_fetcher. Tests reach the snapshots through a test-only `test-snapshots` feature on ccusage-core, enabled from [dev-dependencies], which Cargo leaves out of `cargo build`, so neither the layers nor the shipped binary compile it. The artifact layers no longer receive CCUSAGE_PRICING_JSON_PATH or the snapshot JSON, so their derivation paths stay the same across both kinds of snapshot update. The embedded bytes are unchanged: the moved build script produces byte-identical deflated snapshots. antigravity's dev-dependency on the removed fetch-litellm-pricing feature of ccusage-core is dropped; the binary's feature now forwards to the new crate.
The rust skill and the testing reference still described the snapshots as part of ccusage-core. Record where they live now, why snapshot data must stay out of ccusage-core, and that a crate whose tests load pricing enables ccusage-core's test-snapshots feature.
0ac934c to
a36c243
Compare
ccusage performance comparisonPR SHA: Performance comparison skipped. Base package URL was not ready before 300.000s. Fixture performance comparison requires a base package when --base-dir is not provided. Base package: |
ccusage performance comparisonPR SHA: Performance comparison skipped. Base package URL was not ready before 300.000s. Fixture performance comparison requires a base package when --base-dir is not provided. Base package: |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — reviewed the pricing snapshot isolation on perf/isolate-pricing-snapshots (3 commits, reconstructed from the commit range since the base branch is deleted).
- New
ccusage-pricing-snapshotsleaf crate — owns the movedbuild.rs, the committed models.dev JSON, thefetch-litellm-pricingfeature, and three deflated&[u8]constants with no runtime dependencies. ccusage-corebecomes snapshot-free — drops its build script, exposesEmbeddedSnapshotsplusset_embedded_snapshotsbehind aOnceLock, and adds a test-onlytest-snapshotsfallback enabled from[dev-dependencies].- Binary installs snapshots at startup —
main()hands the three constants topricing::set_embedded_snapshotsnext to the existing fetcher setup, and the binary feature now forwards to the new crate. - Crane layers stay cached —
nix/cargo-artifacts.nixstripsCCUSAGE_PRICING_JSON_PATHand the snapshot JSON from layer inputs while keeping the snapshot crate manifests for workspace resolution. - Tooling and docs follow the move —
justfile, lock script,treefmtexcludes,rust-srccomment, crate READMEs, and the rust/testing skills point at the new crate; antigravity's stray fetch-feature dev-dep is removed.
Verified no stale ccusage-core/src/models-dev or ccusage-core/fetch-litellm-pricing references remain, the workspace-root --features fetch-litellm-pricing Windows invocation still resolves against the binary target, and the amp/claude/qwen adapters without the test feature have no load_embedded test usage.
muse-spark-1.3-contributor (free via Pullfrog for OSS) | 𝕏
Upstream tip: c76874e (2026-10-20, chore(pricing): update models.dev snapshot) Previous fork base: 0c58b88 (the upstream commit this fork was synced to) Synced 83 upstream commits on top of 0c58b88: 56 automated pricing snapshot refreshes and the following meaningful ones: 1cd29f5 chore(deps): update pnpm to v12.13.0 (ccusage#1907) e4f63ba chore(deps): update node.js to >=24.22.0 (ccusage#1908) 130e502 ci: regenerate bun.nix automatically (ccusage#1909) 259ec33 feat(adapter): report stored cost in JSON model breakdowns (ccusage#1903) c1eb448 chore: release v20.0.35 (ccusage#1901) 2a0875f ci(pricing): update snapshots on push to main and daily instead of hourly (ccusage#1914) b090428 chore(deps): update github/codeql-action action to v4.39.0 (ccusage#1912) 4dcf7f5 fix(nix): pin models-dev-gen remeda to models.dev's version and stop Renovate drift (ccusage#1915) 46edb28 fix(nix): stop the dev shell from copying the whole repository (ccusage#1917) 58ec8f1 fix(nix): let commits succeed in worktrees without a loaded dev shell (ccusage#1920) a570a6f fix(nix): vendor Cargo deps without import-from-derivation (ccusage#1918) f6d28c5 fix(antigravity): map model IDs 1418/1419 to gemini-4-argon (ccusage#1905) ce439e5 fix(antigravity): map model ID 1050 to gemini-3.1-flash-lite (ccusage#1902) e62a66f chore(deps): update pnpm to v12.14.0 (ccusage#1923) 117ae68 ci(nix): make the macOS Nix cache save a trimmed store with the Crane layers (ccusage#1921) 7a063a0 ci: shorten the Windows native build critical path (ccusage#1924) 85ebca3 perf(rust): move pricing snapshots into a leaf crate (ccusage#1922) 8fe3f47 perf(nix): build Crane layers with the binary's feature resolution (ccusage#1925) ac289aa perf(pricing): give the pricing refresh a verify-only TLS 1.3 rustls provider (ccusage#1927) d097f74 chore(deps): update rust crate rustls to 0.23.46 (ccusage#1928) f8aaf89 docs: use the compact pkg.pr.new URL for bunx previews [ci skip] (ccusage#1929) f56bb3d chore: release v20.0.36 (ccusage#1916) aaafb41 chore(deps): update dependency vitepress-plugin-group-icons to ^1.8.1 (ccusage#1931) 0861e7f fix(claude): count requestless resp_ content blocks once (ccusage#1935) 867c9f3 chore: release v20.0.37 (ccusage#1933) fa40bfd chore(deps): update songmu/tagpr action to v1.21.3 (ccusage#1937) de99d15 chore(deps): update rust crate zstd to 0.14.3 (ccusage#1936) Fork wins kept: the SQLite on-disk cache with --live-only and the per-namespace ledger, the pi adapter and its per-path namespaces, the OpenCode V2 loader, the FxHash/Cow hot paths, the table renderer, clear-cache, and the tag-only release workflow. Upstream's own release and tagpr machinery stays out. Hand-resolved conflicts: rust/adapters/claude/src/lib.rs: upstream's resp_ message-id dedupe (ccusage#1935) lands beside the fork's requestless replay and collapse_replays rules. rust/adapters/claude/src/README.md: upstream's wording for the msg_/resp_ exception. rust/Cargo.toml: zstd 0.14.3, keeping the fork's exact `=` pin style. .github/workflows/release.yaml: the fork's tag-only release, without upstream's tagpr job or the songmu/tagpr action bump. apps/ccusage/package.json, docs/package.json, package.json: keep 20.0.34; upstream's 20.0.37 bump is dropped. packages/ccusage-*/package.json (6 files): stay deleted; the fork ships no npm wrapper packages and the release workflow does not read them. rust/adapters/claude/src/daily.rs: stays deleted; the fork's daily path lives in lib.rs and shares the dedupe helper the fix changes. Fixes made while landing this sync, folded in so the merge stands green on its own: fix(ci): save the Nix store from the native build composites. The nested cache-nix-action read an empty primary-key at post-job and every native build failed; upstream's defer-save pattern is the fix. fix(rust): keep the agent-recorded cost for deleted sources. The recorded_cost ledger column carries it, so storedCost survives a deleted file. The ledger schema version stays at 2: the column is not a LedgerEntry field, so the blob layout is unchanged and the previously released binary keeps working. fix(rust): make the file fingerprint helper private, the one hawk finding. It is inherited from the pre-sync master, not introduced here. Keep 20.0.34 numbering; DO NOT push a v20.0.34 tag from this fork (release.yaml would publish fork bytes under upstream identity).

Summary
Most commits that land on
mainare the scheduledchore(pricing): update models.dev snapshot/update LiteLLM snapshotcommits (776 of the last 878 first-parent commits). Each one invalidated thefoundationandadaptersCrane layers. As a result, every PR opened after one of those commits rebuiltccusage-core, every adapter, the config-schema generator, and the clippy/hawk/test bases, even when the PR touched no Rust.This PR moves the snapshot data into a new leaf crate,
ccusage-pricing-snapshots. Only the binary depends on it, so a snapshot refresh now changes only the finalccusagederivation (and the test derivation, which builds the whole workspace anyway).Evidence (before)
I compared
drvPaths withnix evalonf6d28c56(aarch64-darwin), before and after a simulated update:models-dev-pricing.json+newline--override-input litellm(patched copy)hb71ghcg…hb71ghcg…(same)hb71ghcg…(same)ny2qqzh4…rcddc4mj…changed0bhh48gk…changedbj2ym9f8…b0b9m72c…changedi0v49lls…changedp973nwwv…Causes:
nix/cargo-artifacts.nixputmodels-dev-pricing.jsonandmodels-dev-catalog-rules.jsoninto every layer's source.ccusage-core/build.rsembeds them, so Cargo reruns the build script and then recompilesccusage-coreand everything that depends on it.CCUSAGE_PRICING_JSON_PATH(the litellm input) stayed inartifactCommonArgs. It was only stripped from the deps-only args, so a lock bump changed every layer's environment.ccusage-core's build script also declaresrerun-if-env-changedfor it.What changed
rust/crates/ccusage-pricing-snapshots: it owns the movedbuild.rs(unchanged apart from its test import), the committedmodels-dev-pricing.json/models-dev-catalog-rules.json, and thefetch-litellm-pricingfeature. It exports three&[u8]constants and has no runtime dependencies.ccusage-coreno longer has a build script. It exposespricing::EmbeddedSnapshotsandpricing::set_embedded_snapshots, whichmain()calls next to the existingset_json_fetcher.test-snapshotsfeature onccusage-corefalls back to the snapshot crate when nothing was installed. Crates whose tests load pricing enable it from[dev-dependencies]. Cargo does not activate dev-dependency features forcargo build, so the layers and the shipped binary never compile it.nix/cargo-artifacts.nix: layers dropCCUSAGE_PRICING_JSON_PATHand the snapshot JSON. They still include the new crate's manifest and.rsfiles, becauseccusage-coredev-depends on it and Cargo resolves the whole workspace.ccusage-core/fetch-litellm-pricingis removed. Before this change it pulled the rustls build stack into everycargo test --workspacecore build. The binary'sfetch-litellm-pricingfeature (used by the Windows build) now forwards to the new crate.justfile(gen-models-dev-pricing),.github/scripts/update-models-dev-lock.nu,nix/treefmt.nix(typos excludes),nix/rust-src.nix, the crate READMEs, and the rust/testing skills.Evidence (after)
Rebased on
12dfc20e:models-dev-pricing.json+newline--override-input litellm7nq7vmr9…62mks729…a1kxdf5r…i6zz2741…s3rs3acy…lzl24hjm…The foundation
drvPathwas also identical before and after rebasing across the real12dfc20emodels.dev snapshot commit. Editingmodels-dev-catalog-rules.jsonlikewise left foundation/adapters unchanged.After building
.#ccusage, I simulated a snapshot change and rebuilt. Onlyccusage-20.0.35.drvwas built (36.6s wall locally on a busy machine), with no foundation or adapters derivation. I also listed the foundation/adapterstarget.tar.zstarchives: the onlyccusage-pricing-snapshotsentries are Crane'sdummyBuildones from the deps layer.The embedded payload is byte-identical. The deflated
litellm-pricing,models-dev-pricing, andmodels-dev-catalog-rulesoutputs fromccusage-core's build script atf6d28c56match the new crate's outputs by SHA-256 (e632d11f…,cf148b37…,11bf0111…).Not fixed here: the final layer still rebuilds core and every adapter
While measuring this, I found that the final
cargo build -p ccusage --bin ccusagere-checks/recompilesccusage-coreand all adapters even when the layers are fresh. This already happens onmain: I reproduced it withcargo checkon the same-psequence the layers use, atf6d28c56. The cause is feature unification. The layer builds resolve features for a subset of the workspace, and the final graph adds e.g.ureq→flate2→miniz_oxide/simd,synfeatures fromschemars_derive, andlibc/default. That changes the metadata hash ofserde,miniz_oxide, etc., soccusage-corebecomes a different unit. So for the final binary, this PR saves the layer builds themselves (CI measured foundation 9s + adapters 4.5s on mac-arm64, 33s + 8s on linux-arm64, plus the test job's layer rebuilds and the config-schema generator in preflight). It does not shrink the final layer. Making the layers reusable by the final build (for example a workspace-hack crate, or building the layers with the binary's feature set) is a separate follow-up.Testing
nix evaldrvPath comparisons above (before/after, both update kinds)nix build .#ccusage, then rebuilt after a simulated snapshot change (only the final derivation rebuilt)ccusage daily --offline --json --breakdown --mode calculatepricesclaude-sonnet-4-20250514(LiteLLM),claude-opus-4-8, andglm-5from the embedded snapshotscargo fmt --all --check,cargo clippy --workspace --all-targets -- -D warnings,just hawk(0 findings),just fmt(no changes)cargo test --workspacewithHOMEpointed at an empty dir andXDG_DATA_HOME/XDG_CONFIG_HOME/CLAUDE_CONFIG_DIR/CODEX_HOMEunset: 1033 passed, 0 failedXDG_DATA_HOMEpointed at an empty dir, because the adapter-all tests otherwise read the developer's real OpenCode dataSummary by cubic
Moves pricing snapshot data into a new leaf crate,
ccusage-pricing-snapshots, so scheduled snapshot-refresh commits no longer invalidate the foundation and adapters Crane layers. Those commits (776 of the last 878 onmain) previously recompiledccusage-core, every adapter, and the config-schema generator; now a snapshot refresh rebuilds only the final binary derivation. This also cuts CI build and cache time: a minimal rustup profile skips rust-docs (~730 MB), and the macOS and Windows caches are saved only from pushes to main when their dependency keys change.build.rs, the committed models.dev JSON snapshots, and thefetch-litellm-pricingfeature, and exports three byte constants with no runtime dependencies.pricing::set_embedded_snapshots;ccusage-corekeeps the loaders and drops its build script.test-snapshotsfeature onccusage-corefalls back to the snapshot crate when nothing was installed; crates whose tests load pricing enable it from[dev-dependencies], which Cargo leaves out ofcargo build.nix/cargo-artifacts.nixno longer injectsCCUSAGE_PRICING_JSON_PATHor the snapshot JSON into the layers, so their derivation paths are stable across both kinds of snapshot update.This fixes the layer rebuilds but not the final layer: the last
cargo buildstill recompilesccusage-coreand the adapters due to feature-unification differences between the layer build and the full workspace graph. That already happens onmainand is a separate follow-up.Written for commit a36c243. Summary will update on new commits.