Repository navigation
perf(daemon): in-memory artifact index, WAL flush, pack mode (#274) - #278
Merged
Merged
Conversation
Closes the persist-path latency gap from issue #274 by reshaping the write path so both reads and writes stay in memory on the hot path. Daemon (`crates/zccache-daemon/src/server.rs`): - `persist_artifact_payloads` consolidates the three persist call-sites behind one helper. Behind `ZCCACHE_PACK_ARTIFACTS=1` it concatenates every payload of a cache miss into a single `{key}.pack` file with a small `ZCPK` header; `ensure_payloads` transparently falls back to extracting from the pack when the unpacked layout is absent. On a 5-payload workload the bench shows ~2.6× wall-clock improvement because Defender's per-file scan cost collapses with file count. - Background `run_index_writer` task drains an in-memory `HashMap` WAL and snapshots to disk on a timer (`ZCCACHE_WAL_FLUSH_MS`, default 5 s) or eagerly at `ZCCACHE_WAL_MAX_PENDING` (default 2048). The persist semaphore (`ZCCACHE_STORE_WORKERS`, default 8) no longer blocks on the index commit. Shutdown notifies the writer for a synchronous final flush bounded by a 2 s timeout. Artifact store (`crates/zccache-artifact/src/store.rs`): - Replaces the redb-backed implementation with a `DashMap` snapshotted to a bincode blob (`index.bin`) via temp+rename. All mutators are now infallible in-memory ops; only `flush()` touches disk. Drops per-txn fsync overhead and lets the hot path skip the redb lock entirely. Includes 13 unit tests for round-trip, corruption tolerance, and atomic replacement. Index path (`crates/zccache-core/src/config.rs`): - `index.redb` → `index.bin`. Existing redb files are orphaned on upgrade; the daemon rebuilds the index by re-missing affected keys (artifact files on disk remain valid). CLI (`crates/zccache-cli/src/main.rs`): - `wait_for_redb_release` → `wait_for_daemon_teardown`: with no file lock to drop, endpoint reachability is the only signal we need. Removed 3 Windows-only tests for redb's exclusive-share semantics. Bench harness: - `crates/zccache-daemon/tests/persist_pool_bench.rs` — Rust microbench that drives several persist strategies side-by-side over realistic synthetic workloads, gated behind `#[ignore]`. Used to pick the defaults above. - `bench/persist-rust-project/` — minimal standalone crate (~10 dummy-linked deps) for end-to-end cold-build measurement. Env vars (all documented in `server.rs` doc comments): - `ZCCACHE_STORE_WORKERS` (default 8) - `ZCCACHE_WAL_FLUSH_MS` (default 5000) - `ZCCACHE_WAL_MAX_PENDING` (default 2048) - `ZCCACHE_PACK_ARTIFACTS` (default off) ~1300 workspace unit tests pass. `cargo clippy --workspace --all-targets -- -D warnings` clean. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
zackees
force-pushed
the
perf/persist-path-issue-274
branch
from
May 19, 2026 06:39
3c8ea6c to
b98a600
Compare
The `tests::warm_*` and `tests::adversarial_*` suites construct fake artifact stores in test temp dirs and pass them to `warm_target`. They previously hardcoded `index.redb` and relied on `store.insert` writing synchronously. After dropping redb: - Hardcoded `index.redb` paths updated to `index.bin`. `cmd_warm` now uses `index_path_from_cache_dir` for consistency with the daemon. - Each `make_test_store` and inline test setup now calls `store.flush().unwrap()` before `drop(store)` so the on-disk blob exists when `warm_target` opens it. Without this, the tests pass locally on Windows (where the file may flush via a different path) but fail on Linux CI with "no artifact index at ...". Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Release for the persist-path improvements + index store refactor landed in this PR (#278): in-memory artifact index with periodic bincode flush, WAL writer, env-tunable persist semaphore, and pack-mode (env-gated). Replaces the redb-backed `ArtifactStore` with a `DashMap` snapshotted atomically to `~/.zccache/index.bin` — a user-visible filename change (legacy `index.redb` files are left orphaned and can be cleaned via `zccache clear`). Merging this commit to main triggers `release-auto.yml`, which detects the workspace version delta and publishes wheels + crates artifacts. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This was referenced May 19, 2026
zackees
added a commit
that referenced
this pull request
May 19, 2026
When `cache-target: "true"` + `target-restore-fallback: "true"` are set, the action restores a `target/` snapshot from a previous commit that shared the same `Cargo.lock`. The post-restore step touched *every* file in `target/` to `now + 1 minute` so cargo's "output mtime > source mtime" check would treat the restored artifacts as up-to-date. The problem: that touch also hits `target/debug/.fingerprint/<crate>-*/`, which contains the dep-info files cargo uses to decide whether to invoke rustc at all. Future-stamping them makes cargo trust the cached binary even when the source has changed — silently linking the *previous* commit's compiled binary against the current source layout. Symptoms observed in PR #278: identical failures on all three test workflows (linux/macos/windows) with panic line numbers and error strings matching the previous commit's source, not the just-pushed source. Fix: exclude `*/.fingerprint/*` from the stamping pass. Output files (rlib/rmeta/build artifacts) still get the future stamp so the original "output newer than source" optimization works for unchanged crates. Fingerprint dep-info files keep their original mtimes from when the snapshot was saved — older than newly-checked-out changed sources, so cargo correctly detects the change and re-invokes rustc. Verification: after this lands, a contributor pushing a single-line edit to a test file should see that change reflected in CI test output. The PR-278 workaround of bumping `Cargo.lock` to bust the restore-key chain is no longer necessary for source-only changes. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
4 tasks
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.
Closes #274.
Summary
HashMapand snapshots the artifact index to a bincode blob (index.bin) on a 5 s timer / 2048-entry budget. Persist call-sites send + return; the disk-write semaphore no longer blocks on the index commit.ZCCACHE_PACK_ARTIFACTS=1). Concatenates a cache miss's payloads into one{key}.packfile. Microbench shows ~2.6× wall-clock improvement at 5 payloads per job — Defender's per-file scan cost is the bottleneck, and pack mode collapses it with file count.state.artifacts; redb was only doing per-txn fsync on the write side. The newArtifactStoreis aDashMapsnapshotted via temp+rename.kv.rs(separateKvcli subcommand) keeps its redb usage.crates/zccache-daemon/tests/persist_pool_bench.rs(#[ignore]) compares strategies side-by-side.bench/persist-rust-project/is a minimal standalone crate (~10 dummy-linked deps) for cold-build end-to-end measurement.New env vars
ZCCACHE_STORE_WORKERSZCCACHE_WAL_FLUSH_MSZCCACHE_WAL_MAX_PENDINGZCCACHE_PACK_ARTIFACTSBench (Windows 10, Defender on, 16-core)
200 jobs × 5 payloads × 50 MB workload:
200 jobs × 3 payloads × 327 MB workload (bandwidth-bound):
Migration notes
Existing users get a fresh cache index on upgrade — old `index.redb` is orphaned and can be deleted manually or via `zccache clear`. Artifact files on disk are intact and re-discovered as misses repopulate the in-memory index. Documented in `index_path_from_cache_dir`.
Test plan
🤖 Generated with Claude Code