Skip to content

perf(daemon): env-gated ZCCACHE_HIT_TRACE dump for hit-path sub-phase data - #470

Merged
zackees merged 2 commits into
mainfrom
perf/instrument-hash-subphases
May 30, 2026
Merged

zackees merged 2 commits into
mainfrom
perf/instrument-hash-subphases

Conversation

@zackees

@zackees zackees commented May 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds ZCCACHE_HIT_TRACE=1 env-gated stderr dump in pipeline.rs that emits one line per warm hit through the hash-headers slow path with source_us, headers_count, headers_us, hdr_avg_us, and the source path. Lets the perf harness decompose the dominant 995µs metadata cache (source+hdrs) phase into actionable sub-components.

ci/perf_local.py now propagates any ZCCACHE_* env var to the in-container daemon, so:

```
ZCCACHE_HIT_TRACE=1 uv run python ci/perf_local.py --scenario cold-tar-untar-warm --fixture medium
```

…produces per-hit lines you can pipe through awk/grep to histogram which compiles are paying the most for header re-hashing.

Why

The metadata cache (source+hdrs) phase (= hash_source_ns + hash_headers_ns) dominates the warm hit budget at 5.6× the next phase. Without sub-phase data we can't tell if the cost is:

  • One pathological source file with many headers
  • Many small files each adding rayon dispatch overhead
  • Metadata-cache stat-verify routinely failing → forced re-hash

The dump gives us the per-call shape directly. Findings feed into follow-up issues (#469 already filed: the slow-path is dominating because mtime-precision asymmetry causes stat-verify to fail post-tar/untar).

Cost

One std::env::var_os call per warm hit (~50ns) when the env is unset — negligible. When set, one eprintln! per non-fast-hit compile.

Test plan

  • soldr cargo check -p zccache
  • Docker run with ZCCACHE_HIT_TRACE=1 confirms the env var propagates into the container

Closes #468

🤖 Generated with Claude Code

zackees and others added 2 commits May 30, 2026 10:48
)

Add `ZCCACHE_HIT_TRACE=1` env var that makes the daemon emit a one-line
stderr summary per warm hit through the slow path (hash source + hash
headers). Lets the perf harness decompose the dominant
"metadata cache (source+hdrs)" phase (995µs/event on the canonical
cold-tar-untar-warm/medium scenario, 5.6× larger than the next phase).

Output shape:

  ZCCACHE_HIT_TRACE source_us=12 headers_count=47 headers_us=983 \
                    hdr_avg_us=20 source_path=/path/to/foo.cc

Pipe through `awk '/ZCCACHE_HIT_TRACE/'` over a session's daemon log
to histogram which compiles have the highest header count and
per-header cost — informs whether the slow path is dominated by
header count (parallelism overhead) or per-header rehash work.

Also: `ci/perf_local.py` now passes through any `ZCCACHE_*` env var
to the Docker container so the in-container daemon inherits the flag.

The env check is one `var_os` probe per warm-hit (~50ns); cost is
negligible when the flag is unset.

Closes #468

Co-Authored-By: Claude Opus 4.7 <[email protected]>
The earlier `let mut hit_trace_headers_count: usize = 0;` at the top
of the if/else triggered `value assigned ... is never read` on the
context_is_cold branch (the value is only read inside the else block
where it's also written). Move the binding inside the else.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@zackees
zackees merged commit 11e9080 into main May 30, 2026
31 checks passed
@zackees
zackees deleted the perf/instrument-hash-subphases branch May 30, 2026 18:06
zackees added a commit that referenced this pull request Jun 19, 2026
…#781)

First zccache surface that calls the v2 broker API. New module
`zccache::ipc::broker_v2` with `connect_v2_broker(wanted_version) ->
Result<ClientSession, BrokerV2Error>` wrapping
`running_process::broker::client_v2::connect("zccache", ...)`.

Also bumps the [patch.crates-io] running-process pin to e64f6ff to
pick up running-process #492 (BackendHttpReady plumbing), #493
(GetBrokerHttpEndpoint RPC dispatch), #494 (env overrides), #495
(broker HTTP server scaffold), and #496 (aggregator page top-bar +
iframe) — all of which are in-tree but unreferenced by zccache yet.

v1 callers are deliberately untouched: v2 ships alongside v1 per the
coexistence table in upstream #470. Each subsequent slice replaces
one more of zccache's 62 v1 broker references with a v2 path.

One unit test covers the typed BrokerV2Error::Dial path with no
broker running — the same shape the rest of the migration will
pattern-match on.

Refs #777

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit that referenced this pull request Jun 20, 2026
…lice 24 of #782) (#857)

zccache#782 slice 24 — completes the v1→v2 import migration for
broker-side process identity. Five call sites swap their import
path from \`running_process::broker::backend_handle::*\` to
\`running_process::broker::protocol_v2::backend_handle::*\`:

- \`ipc/mod.rs\`: \`running_process_endpoint\`, \`current_backend_identity\`,
  \`write_backend_identity\`, \`probe_backend_handle\` (4 signatures)
- \`daemon/server/state.rs\`: \`backend_identity: DaemonProcess\` field
- \`daemon/server/lifecycle.rs\`: \`backend_identity()\` getter

Per upstream PR #527 (slice 23-B), the v2 namespace types are
TypeId-identical to v1's — these symbols are intentionally
cross-version-stable per #470's coexistence design. The migration
is a pure import swap with zero behavioural change.

## Why this matters

Removes 5 v1 \`broker::backend_handle::*\` import paths from zccache
production code. The remaining v1 imports in broker.rs (adopt /
client / BrokerClientError) require actual v2 broker scaffold
functionality (accept loop, hello router consuming v2 servicedef
files) that's still in flight upstream — those are slice 25.

After this slice, the only v1 \`broker::backend_handle::*\` reference
in zccache is the manifest.rs doc comment, which is informational.

## Pin bump bundled

Bumped \`running-process\` pin to \`d0299b3\` (post-#527 main).

## Test plan

- [x] \`soldr cargo clippy -p zccache --all-targets -- -D warnings\` clean.
- The upstream TypeId-equality test (\`v1_and_v2_backend_handle_types_are_the_same\`
  in #527) guarantees the swap is behaviour-preserving — zccache's
  test suite would catch any drift if the upstream types accidentally
  forked.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(daemon): instrument hash_source/hash_headers sub-phases — they dominate warm hit at 995us

1 participant