Repository navigation
Conversation
`.icp/cache/artifacts` held one whole copy of the module per canister, so several canisters built to the same WASM (one pre-built module shared by many canisters, say) each cost its full size on disk. The store now keeps a module at `modules/<sha256>.wasm` and a small `refs/<canister>` file naming it. Saving bytes already present writes only the ref; a module is removed when the last canister naming it is rebuilt to something else. The change is inside `ArtifactStore`: the `store_artifact::Access` seam and its callers are untouched. Artifacts written by an earlier version are not read, and each is removed as its canister is rebuilt. Co-Authored-By: Claude Fable 5.2 <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Non-UTF-8 artifact refs cause errors instead of being treated as invalid, preventing rebuilds from repairing malformed entries without manual deletion.
1 open issue
What changed in this PR
This PR reduces artifact-cache storage by keeping one owned copy of each distinct WASM module, while leaving the artifact-store interface and callers unchanged.
Changes:
- Stores modules by SHA-256, with a small reference file per canister.
- Removes replaced modules once unreferenced and clears legacy artifacts as canisters rebuild.
- Adds host-store tests and documents the new layout and upgrade behavior.
| File | Description |
|---|---|
docs/concepts/project-model.md |
Clarifies that distinct built WASM files are stored once. |
crates/icp-project/src/store_artifact.rs |
Implements shared module storage, reference lookup, cleanup, and tests. |
CHANGELOG.md |
Documents deduplication and the rebuild requirement after upgrading. |
Review effort: Balanced
…eanup A ref holding bytes that are not UTF-8 failed to read, which failed both that canister's rebuild and any other canister's save that scanned it. It now reads as holding no module, like any other malformed ref. The store's two directories are `.modules` and `.refs`: a canister name cannot contain `.`, so neither can be where an earlier version left a canister's artifact file. With that, the code that moved such files out of the way is gone; they are left in place and not read. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
On the Before this PR the store kept each canister's module in a file named for the canister, directly in Canister names may only contain ASCII letters, digits, The cost is that the two directories are hidden from a plain |
…or once The round-trip and earlier-version tests repeated what the others already cover, and the unchanged-rebuild case is now one save in the sharing test. The store's own cause was being wrapped in a second StoreCause on its way into SaveStore and LookupStore. Co-Authored-By: Claude Fable 5.2 <[email protected]>

Intent
Stop
.icp/cache/artifactsholding a full copy of the same WASM for every canister built from it. On a memory-backed disk each copy is RAM.Supersedes #883, which reached the same goal by having the store record a link to a pre-built module's source file. This takes the other route: the store still owns its bytes, but owns each distinct module once.
What changed
The store's layout, inside
ArtifactStoreonly:savehashes the bytes, writes the module only if it is not already there (to a.partialfile, then renamed into place), and writes the canister's ref.lookupreads the ref, then the module. A missing ref, a ref that is not a SHA-256 (non-text bytes included), or a ref whose module is gone all read as "not built", and a rebuild replaces it.., which a canister name cannot contain, so neither can collide with an artifact file an earlier version left for a canister.store_artifact::Accessseam, the in-memory mock, and every caller (build, install, candid check, bundle,canister call) are unchanged.Compared with #883
.icp.icpself-containedBuildreturnsModule, newAccess::linkWhat this does not do, and #883 did: a
pre-builtstep still copies its module to the scratch directory, andbuildstill reads it into memory before saving. That copy is transient (it goes when the build ends). Removing it needs the build step to hand back a path instead of writing to the output, which can follow separately without the link or the install-time check.Behaviour to know about
icp canister installreports a canister as not built untilicp build(oricp deploy) has run. The old files are left in place and not read; nothing in the CLI clears.icp/cache/artifacts, so they stay until it is deleted by hand.Testing
cargo test -p icp-projectwith and without default features,cargo clippy --workspace --all-targets, and thewasm32-unknown-unknownclippy all pass.build_adapter_testsandbuild_testspass against the built binary.pre-builtcanisters and one script canister producing the same bytes left one module and three 64-byte refs; changing the script canister's output added a second module and kept the shared one;icp project bundleread both back.scripts/check-no-host-reach.sh(needsllvm-nm, not installed here). The change is entirely behind thehostfeature, and CI runs the check.🤖 Generated with Claude Code