Repository navigation
perf(daemon): defer depgraph load to spawn_blocking — closes #640 herd - #648
Merged
Merged
Conversation
The first-wave daemon herd #637 / #640 finally collapses. With #642's ArcSwap<DepGraph> foundation in place, `set_dep_graph` is `&self` + atomic, so the on-disk depgraph load can fire from `tokio::task::spawn_blocking` AFTER `server.run()` has started the accept loop. ## Order of operations on a winning daemon (after this PR) Cold start, daemon binary started by a CLI spawn: 1. crash guard, "starting" log 2. **Pre-bind probe (#641)** — quick check for an existing serving daemon 3. defender banner 4. tokio runtime built 5. `rt.block_on(async { ... })`: a. **`DaemonServer::bind(endpoint)` — pipe claimed at t ≈ 0** b. On bind error: #639's PermissionDenied/AlreadyExists/AddrInUse → INFO + exit 0; other → ERROR + exit 1 c. **Winner-only**: write spawn event + lock file d. **`tokio::task::spawn_blocking(load_depgraph_and_install)`** — fires in parallel with accept loop e. Ctrl+C handler spawned f. **`server.run(idle_timeout)` — accept loop runs immediately** g. When the spawn_blocking task finishes (~3 s on a populated cache), it calls `DepGraphSetter::install(graph, warning)` which `ArcSwap::store`s the new graph Compile requests arriving during step (f) but before (g) see the empty default `DepGraph` and take the cold-path miss. That is correct — the `cache_system`'s stat-verify safety net catches any stale-hit risk; we lose ~3 s of cache hits per cold start, which is exactly what the user was paying anyway under the old broken-herd flow. ## Order of operations on a redundant daemon The 277-daemon herd shape from #637 collapses to ~2 across both waves of the user's repro: - **First wave** (initial cohort, no lock file yet): N daemons all race at step 5a. One wins; the other N-1 hit #639's PermissionDenied path at step 5b in microseconds and exit 0. Critically, none of them paid the depgraph load cost — the bind is the first I/O after process start. - **Second wave** (spawned by clients whose connect failed mid-load on the winner): caught at step 2 by #641's pre-bind probe. ## Why this didn't ship in v1 of #639 The first attempt at bind-before-load broke `wrapper-e2e (windows-latest)`: the pipe was bound but accept hadn't started, so clients connected fast, sent a message, then timed out after 10 s waiting for a response that no one was reading. This PR keeps the bind + accept on the same timeline (both inside `rt.block_on`); only the depgraph load moves to a background task. Accept starts at the same instant it always did relative to bind. The reason this couldn't be done before #642: `set_dep_graph` used `Arc::get_mut`, which only works pre-`run()`. ArcSwap removed that constraint. This PR is exactly the follow-up #642's commit message promised. ## New types / API - `daemon::DepGraphSetter` — owned handle that survives `spawn_blocking` boundaries. Holds a clone of the daemon's `Arc<SharedState>`; calls `state.dep_graph.store(...)` + `state.depgraph_load_warning.blocking_lock()` on `install()`. - `DaemonServer::dep_graph_setter() -> DepGraphSetter` — public method to hand out the setter before calling `run()`. - `DaemonServer::set_depgraph_load_warning` is now `&self` + uses `tokio::sync::Mutex::blocking_lock` (matching the field's existing type). Same change shape as `set_dep_graph` in #642. ## Tests - All 1693 pre-existing lib tests pass. - Live-spawn-race repro is intrinsically flaky as a unit test (depends on real Windows pipe scheduling), so coverage is the structural one: "is there any blocking I/O between `rt.block_on(async)` entry and `DaemonServer::bind`?" — answer after this PR: no. ## Test plan - [x] `soldr cargo check -p zccache --tests` clean - [x] `soldr cargo clippy -p zccache --tests -- -D warnings` clean - [x] `soldr cargo fmt --all -- --check` clean - [x] `soldr cargo test -p zccache --lib` — 1693 / 1693 pass - [ ] PR CI green — particularly `wrapper-e2e (windows-latest)`. The v1 #639 regression was "bound pipe, no accept" for 3+ s. This PR keeps bind and accept on the same timeline (both inside `rt.block_on`), so the regression shape should not recur. Closes #640 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This was referenced Jun 4, 2026
Closed
zackees
added a commit
that referenced
this pull request
Jun 4, 2026
Ships #649 (zccache m e s o n configure wrapper, closes #627), #650 (perf: single-pass output-meta build), #651 (test: cross-key contention), #648 (closes #640). The headline payload is #649 — the wrapper was merged 2026-06-04 but the 1.11.11 release was tagged 2026-06-03, so downstream pyproject pins on >=1.11.11 do not currently see it. This release closes that gap. Validated end-to-end against FastLED on Windows.
2 of 7 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.
Summary
The first-wave daemon herd from #637 / #640 finally collapses. With #642's
ArcSwap<DepGraph>foundation in place,set_dep_graphis&self+ atomic-swap-safe, so the on-disk depgraph load can fire fromtokio::task::spawn_blockingAFTERserver.run()has started the accept loop.Order of operations on the winning daemon
DaemonServer::bind(endpoint)— pipe claimed at t ≈ 0DepGraphSetter::installswaps inCompile requests arriving during step (5e) before (5f) see the empty default
DepGraphand take the cold-path miss. That is correct — thecache_system's stat-verify safety net catches any stale-hit risk; we lose ~3 s of cache hits per cold start, which is exactly what the user was paying anyway under the old broken-herd flow.Order of operations on redundant daemons
The 277-daemon herd shape collapses to ~2 across both waves:
Why this didn't ship in v1 of #639
The first attempt at bind-before-load broke
wrapper-e2e (windows-latest): the pipe was bound but the accept loop hadn't started, so clients connected fast, sent a message, then timed out after 10 s waiting for a response that no one was reading.This PR keeps the bind + accept on the same timeline. Both happen inside
rt.block_on; only the depgraph load moves to a background task. Accept starts at the same instant it always did relative to bind. The v1 #639 regression shape doesn't recur.The reason this couldn't be done before #642:
set_dep_graphusedArc::get_mut, which only works pre-run(). ArcSwap removed that constraint. This PR is exactly the follow-up #642's commit message promised.New types / API
daemon::DepGraphSetter— owned handle that survivesspawn_blockingboundaries. Holds a clone of the daemon'sArc<SharedState>; callsstate.dep_graph.store(...)+state.depgraph_load_warning.blocking_lock()oninstall().DaemonServer::dep_graph_setter() -> DepGraphSetter— public method to hand out the setter before callingrun().DaemonServer::set_depgraph_load_warningis now&self+ usestokio::sync::Mutex::blocking_lock(matching the field's existing type). Same change shape asset_dep_graphin refactor(state): wrap state.dep_graph in ArcSwap — foundation for #640 #642.Test plan
soldr cargo check -p zccache --testscleansoldr cargo clippy -p zccache --tests -- -D warningscleansoldr cargo fmt --all -- --checkcleansoldr cargo test -p zccache --lib— 1693 / 1693 passwrapper-e2e (windows-latest). The v1 fix(daemon): pipe-in-use bind error → INFO + exit 0 (partial #637) #639 regression was "bound pipe, no accept" for 3+ s. This PR keeps bind and accept on the same timeline (both insidert.block_on), so the regression shape should not recur.A live-spawn-race repro is intrinsically flaky as a unit test (depends on real Windows pipe scheduling), so coverage is the structural one: "is there any blocking I/O between
rt.block_on(async)entry andDaemonServer::bind?" — answer after this PR: no.Closes #640
🤖 Generated with Claude Code