Skip to content

perf: compute engine and dispatcher speedups + backend-metadata cache fix - #6180

Merged
baszalmstra merged 5 commits into
prefix-dev:mainfrom
baszalmstra:bz/perf-cluster
May 28, 2026
Merged

baszalmstra merged 5 commits into
prefix-dev:mainfrom
baszalmstra:bz/perf-cluster

Conversation

@baszalmstra

Copy link
Copy Markdown
Contributor

Description

A cluster of perf wins in the compute engine and command dispatcher:

  • Skip cycle-detection edge install on cache hits in the compute engine.
  • Install the active edge before spawning child branches so the parent isn't held while children fan out.
  • Hash SourceMetadata records by Arc identity to dedup record assembly across nested solves.
  • Identity-based Hash on PixiRecord / SourceRecord, plus LockFileWriter dedup.
  • Cache system-backend binary fingerprints so the same pixi-build-* binary isn't re-probed across envs.
  • Parallelize the build solve with host prefetch, and quiet the noisy per-env tracing.

Also includes one correctness fix: the build-backend-metadata cache freshness check was comparing absolute walked paths against relative cache entries, so every glob hit looked like a new file and over-invalidated the cache.

What this enables: pixi lock and pixi install get noticeably faster for workspaces with many environments or many source backends. No protocol or schema surface changes.

How Has This Been Tested?

cargo check --workspace --tests on Windows. Local pixi lock runs on the workspaces I have on hand (including ROS nav2) showed the expected speedup with no behavioural regression.

AI Disclosure

  • This PR contains AI-generated content.
    • I have tested any AI-generated content in my PR.
    • I take responsibility for any AI-generated content in my PR.

Tools: Claude (Sonnet/Opus 4.x via Claude Code)

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas

@baszalmstra
baszalmstra force-pushed the bz/perf-cluster branch 3 times, most recently from 32e9c24 to 476a98e Compare May 22, 2026 10:00
@baszalmstra
baszalmstra requested a review from hunger May 22, 2026 10:38
@baszalmstra
baszalmstra marked this pull request as draft May 22, 2026 10:42

@hunger hunger left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nit, LGTM.

/// disabling the cache for this backend.
fn resolve_executable_path(cmd: &str) -> Option<PathBuf> {
which::which(cmd).ok()
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? Feels like fluff to me.

@baszalmstra
baszalmstra force-pushed the bz/perf-cluster branch 3 times, most recently from db8bebf to d2f5050 Compare May 22, 2026 13:21
… hits

`ctx.compute(&K).await` was paying two costs on a cache hit:
1. `install_active_edge()` locked a single global parking_lot::Mutex over
   the active-edge graph and ran a BFS over all currently-outstanding
   edges to detect cycles, then dropped the edge immediately because
   the lookup found a Lookup::Completed value with nothing to await.
2. The wrapping Future still had to be polled by tokio.

Under fan-out (navigation2: ~80 concurrent solve tasks + ~40 backend
metadata calls), many threads contended on that single global mutex while
each ran the BFS under it. Measured: `compute(&ChannelConfigKey).await`
took 37 seconds on the top-level solve, while the actual rattler solver
work was only 1.2s.

Fix: reorder `ComputeCtx::resolve()` to look up the per-type slot first
and short-circuit on Lookup::Completed. Only install the active edge on
Lookup::InFlight, where the wait is real and cycle detection is actually
load-bearing.

Verified post-fix that install_active_edge never exceeds 1ms across the
entire navigation2 lock, so this is the right floor: a lockfree refactor
of ActiveEdges would not measurably help.

Also verified that an alternative fix (a new `ctx.read::<K: InjectedKey>`
API that bypasses compute() entirely for injected singletons) is
redundant once resolve() short-circuits cache hits: a/b test with all 11
`ctx.compute(&InjectedKey).await` sites converted to `ctx.read(&K)` was
within run-to-run noise of the resolve()-reorder-only configuration.

Result on navigation2 (PIXI_BUILD_BACKEND_OVERRIDE_ALL=1, fresh lock):
   total lock          5m 52s   -> 3m 06s    (-47%)
   walk_and_resolve    181s     -> 93s
   top-level solve     171s     -> 96s
   channel_config_elapsed_ms per solve   3-37s -> 0ms
   install_active_edge >1ms             many  -> 0

All cycle-detection unit tests pass.
The previous order (spawn future, then install active edge only on
Lookup::InFlight) opened a race window: tokio could start the child's
task on another worker before the parent finished install_active_edge,
the child could recursively spawn descendants, and a descendant
closing a back-edge would BFS over an active-edge graph that did not
yet contain the parent->child edge -- yielding an undetected cycle
that deadlocked.

Restore the safer ordering: peek the per-type slot with the existing
`lookup` API; on Completed return the value with no edge install
(preserving the cache-hit fast path from the previous commit); on
miss/InFlight install the edge first, then call get_or_insert_with.

Cycle-detection unit tests pass; navigation2 lock no longer wedges
post-satisfiability.
…ntity

Profiling navigation2 showed AnyKeyDyn::dyn_hash dominated by
<SourceRecord as Hash>::hash, reached transitively through
SolveCondaSpec::source_repodata: Vec<Arc<SourceMetadata>>. SourceRecord
derives Hash over its full PackageRecord *plus* build_packages and
host_packages, which are themselves Vec<UnresolvedPixiRecord> that
recurse into more SourceRecords. A single compute-graph lookup of
SolveCondaKey was hashing O(metadata x records x record_fields x
transitive_packages) of data.

Producers already maintain Arc identity: each unique Arc<SourceRecord>
is created exactly once in assemble_source_record_inner, cached as the
value of ResolveSourcePackageKey, and Arc::cloned through every
consumer. So switching SourceMetadata's Hash/Eq to pointer-identity
on `records` is safe and collapses the cost to O(records) per
SourceMetadata. `source` keeps content-hashing as the discriminator.

navigation2 lock measurably faster end-to-end.
…ackend fingerprint cache

Performance:
- pixi_record: non-optional identifier_hash on SourceRecord, computed
  bottom-up at construction. Identity-based Hash/PartialEq/Eq on
  UnresolvedPixiRecord so compute-engine cache lookups and hash_vec in
  installed_source_hints don't recurse through deeply-shared build/host
  package trees.
- pixi_record::lib: LockFileWriter bundles LockFileBuilder with a
  RegistrationCache so shared source subtrees are descended once during
  lock-file write.
- pixi_command_dispatcher::installed_source_hints: Arc-pointer dedup in
  collect() so the read-side flatten is also non-exponential.

Feature: system-backend metadata cache fingerprint
- New BackendBinaryFingerprint(u64) + BackendBinaryFingerprintKey
  compute-engine Key. xxh3 streams the resolved executable in
  spawn_blocking, engine caches per-path within a process.
- BuildBackendMetadataCacheEntry::backend_binary_fingerprint plumbed
  through verify_cache_freshness + CacheProbe::Miss + cache write.
- should_skip_metadata_cache replaced with BackendCacheStrategy:
  package-resolved backends cache as before, system / path-based
  backends now cache with the binary fingerprint as the invalidation
  signal, mutable-environment backends still skip.

Tracing left in walk_and_resolve / RSP / SPEK / cycle guard for future
debugging.

Cargo.lock: bump resolvo 0.10.2 -> 0.10.3.
Quiet a cluster of debug-level tracing emitted per-env (per-package, per-platform) during pixi lock. Verbose enough on large workspaces (e.g. ROS nav2) to dominate the lock's debug output.

Fix: build-backend-metadata cache freshness path was comparing absolute walked paths against relative cache entries, so every glob hit looked like a new file and over-invalidated the cache. Relativize before the membership check.
@baszalmstra
baszalmstra marked this pull request as ready for review May 28, 2026 08:12
@baszalmstra
baszalmstra merged commit 8deabf2 into prefix-dev:main May 28, 2026
69 of 70 checks passed
tenzinplatter added a commit to greenroom-robotics/pixi that referenced this pull request Jun 26, 2026
* fix: don't misclassify missing python as pypi-only during upgrade (prefix-dev#6095)

* chore(docs): Update the pixi publish docs (prefix-dev#6129)

* fix: drop bare self-references in expand_self_extras (prefix-dev#6142)

* chore(ci): Update Pixi (prefix-dev#6149)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(ci): Update GitHub Actions (prefix-dev#6148)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix: use gnu target for riscv64 in install.sh (prefix-dev#6143)

* feat(publish): honor workspace.s3-options when uploading to s3 (prefix-dev#6069)

* feat: add oauth default login (prefix-dev#6140)

* fix: propagate run-exports from host/build  (prefix-dev#6151)

* chore(deps): bump uv to 0.11.15 (prefix-dev#6132)

* perf: install build and host environments concurrently (prefix-dev#6152)

* feat(publish): add `--variant` and `--variant-config` flags (prefix-dev#6109)

* chore(deps): bump rattler crates (prefix-dev#6153)

* docs: Fix typo (prefix-dev#6157)

* feat: add `--package-format` to `pixi publish` for tar.bz2 output (prefix-dev#6156)

* fix: hook up repodata fetch reporter to gateway queries (prefix-dev#6112)

* fix: invalidate build-backend metadata cache when backend spec changes (prefix-dev#6111)

* chore(deps): bump rattler-build crates to latest main (prefix-dev#6163)

Co-authored-by: Claude <[email protected]>

* fix: normalize extras order in lockfile metadata comparison (prefix-dev#6165)

* fix: trust path-based pypi overrides for transitive registry specs (prefix-dev#6169)

* fix: build backends nightly build - pass through more vars to fix sccache (prefix-dev#6168)

* fix: build backends build by disabling env isolation (prefix-dev#6170)

* chore: version to 0.69.0 (prefix-dev#6164)

* fix: conda package build for windows and osx (prefix-dev#6171)

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

* chore: bump backend versions (prefix-dev#6173)

* docs: Update `github_actions` docs for `setup-pixi` version 0.9.6 (prefix-dev#6174)

Co-authored-by: Pavel Zwerschke <[email protected]>

* feat: implement v3 repodata/matchspec support in pixi spec (prefix-dev#6015)

* fix: bump mimalloc to 0.1.51 to fix win-arm64 process-exit crash (prefix-dev#6176)

Co-authored-by: Claude <[email protected]>

* feat: support `[workspace.dependencies]` (prefix-dev#6162)

* fix(pypi-mapping): fetch parselmouth compressed mapping from conda-mapping.prefix.dev (prefix-dev#6172)

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>

* feat: clamp .pixi/ mtimes to SOURCE_DATE_EPOCH for reproducibility (prefix-dev#6056)

* chore(ci): Update azure/trusted-signing-action action to v2 (prefix-dev#6200)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(ci): Update Rust crate shlex to v2 (prefix-dev#6201)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(ci): Update GitHub Actions (prefix-dev#6195)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(ci): Update Pixi (prefix-dev#6196)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix(reinstall): wire up progress reporter and batch environments (prefix-dev#6205)

Co-authored-by: Lucas Colley <[email protected]>

* fix: forward termination signal (prefix-dev#6204)

* fix(global): clear conda stack env for prefix-ignore trampolines (prefix-dev#6210)

Co-authored-by: jinhyuk9714 <[email protected]>
Co-authored-by: GitHub Actions <[email protected]>

* chore(ci): Update taiki-e/install-action action to v2.79.2 (prefix-dev#6209)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* docs: clarify per-environment activation variables (prefix-dev#6214)

Co-authored-by: Claude <[email protected]>
Co-authored-by: Hofer-Julian <[email protected]>

* fix: git url normalization (prefix-dev#6203)

* feat: adopt deno_task_shell native multiline support (prefix-dev#6211)

* fix: installer, use per user scope instead of system (prefix-dev#5568)

* fix: disable gpg signing in git fixture repos (prefix-dev#6216)

Co-authored-by: Claude <[email protected]>

* fix(pixi-build-r): resolve license file to absolute path (prefix-dev#6215)

* chore: use lzma-rust2 instead of xz2 (prefix-dev#5087)

* feat: add skip_pyc_compilation configuration option (prefix-dev#5737)

* chore: use "lock file" consistently (prefix-dev#6208)

* feat(pixi-build): plumb workspace scratch directory and cache ROS distro fetches (prefix-dev#6181)

* docs(cli): mention `pixi self-update` in `requires-pixi` help msg (prefix-dev#6207)

* feat: git lfs support in `pixi-git` (prefix-dev#6183)

* feat: parallel global update (prefix-dev#5970)

* feat(pixi-build-ros): discover sibling ROS packages + marker-driven workspace globbing (prefix-dev#6182)

* docs: Update link to Code of Conduct in CONTRIBUTING.md (prefix-dev#6224)

* fix: tests on main did not update assertion for `.git` suffix (prefix-dev#6227)

* perf: compute engine and dispatcher speedups + backend-metadata cache fix (prefix-dev#6180)

* chore: use rust backend for building ros backend (prefix-dev#6228)

* fix: reject build backends defined as source dependencies (prefix-dev#6230)

* fix: reinstall when registry install collides with non-registry lock entry (prefix-dev#6213)

Co-authored-by: Claude <[email protected]>

* fix: clear error on remove with suggestions for missing dependency (prefix-dev#6218)

Co-authored-by: Claude <[email protected]>

* fix: seed pypi-options from global config in `--import` and existing pyproject paths (prefix-dev#6212)

Co-authored-by: Claude <[email protected]>

* fix: keep OS trust store for native-tls System mode (prefix-dev#6235)

Co-authored-by: Claude <[email protected]>

* feat: support --no-config / --config-file (prefix-dev#6222)

* fix: upgrade dependency-group dependencies (prefix-dev#6241)

* chore: reuse build cache by passing `--workspace` (prefix-dev#6242)

* feat: extend pixi publish to support cloudsmith as a target (prefix-dev#6219)

* chore: version to 0.70.0 (prefix-dev#6244)

* chore(ci): Update cargo patches (prefix-dev#6247)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(ci): Update Pixi (prefix-dev#6248)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(ci): Update GitHub Actions (prefix-dev#6250)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* feat: add --index option to specify PyPI index URL (prefix-dev#5575)

* chore: bump backend versions (prefix-dev#6254)

* fix: scope PyPI source-build cache by conda environment (prefix-dev#6240)

This change scopes the source-build cache to the conda environment, so a wheel built against one set of conda dependencies is no longer reused in an environment that resolves different ones

* fix: limit concurrent global update (prefix-dev#6253)

* fix: global share command dispatcher (prefix-dev#6255)

* docs: link to parselmouth mapping browser in conda/PyPI page (prefix-dev#6256)

* fix(pixi-build-python): reinstall to avoid duplicate dist-info (prefix-dev#6257)

Co-authored-by: Claude <[email protected]>

* feat: implement extras and flags support for pixi and pixi-build (prefix-dev#5998)

Co-authored-by: Bas Zalmstra <[email protected]>

* feat: serialize concurrent environment installs and recover from interrupted ones (prefix-dev#6233)

Co-authored-by: Claude <[email protected]>

* chore(ci): Update Rust crate jiff to v0.2.27 (prefix-dev#6258)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix: support conda extras for satisfiabily and solve groups (prefix-dev#6260)

* chore(ci): Update GitHub Actions to v2.79.9 (prefix-dev#6261)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore: version to 0.70.1 (prefix-dev#6268)

* fix: compare pypi git urls using the raw url, not uv's canonical one (prefix-dev#6272)

Co-authored-by: Claude <[email protected]>

* fix: keep conda-env build discriminator out of PEP 517 config_settings (prefix-dev#6273)

Co-authored-by: Claude <[email protected]>

* fix: accept find-links URLs during lock file satisfiability (prefix-dev#6270)

Co-authored-by: Claude <[email protected]>

* chore: strip debug info from dependencies in dev builds (prefix-dev#6283)

* chore: Bump tikv-jemallocator to 0.7.0 (prefix-dev#6278)

* ci: speed up ubuntu and macOS x86 CI (prefix-dev#6280)

* feat: Improve PyPI > Conda clobber detection (prefix-dev#6292)

* fix(ros): avoid pixi lock panics on unmappable ROS dependencies (prefix-dev#6290)

Co-authored-by: Claude <[email protected]>

* fix: preserve file permissions during atomic write operations (prefix-dev#6296)

* chore: version to 0.70.2 (prefix-dev#6298)

Co-authored-by: Ruben Arts <[email protected]>

* feat(core): Rich Platform support (prefix-dev#6178)

* test: move examples satisfiability tests to Python (prefix-dev#6300)

* fix: honor workspace [cache.*] overrides for conda-pypi mapping cache (prefix-dev#6284)

* fix: stop source builds rebuilding from scratch on every run (prefix-dev#6285)

* fix: suggest the correct cache config key in netfs-redirect warning (prefix-dev#6282)

* test: skip example satisfiability checks on unsupported platforms (prefix-dev#6311)

* chore(ci): Update Pixi (prefix-dev#6305)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(ci): Update cargo patches (prefix-dev#6304)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(ci): Update GitHub Actions to v2.81.1 (prefix-dev#6307)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* refactor: pypi mapping module so that its a bit more logically named (prefix-dev#6302)

* docs: Remove pixi-inject page (prefix-dev#6276)

* chore(ci): Update GitHub Actions to v2.81.2 (prefix-dev#6313)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix(test): make test_info_output_extended platform-agnostic (prefix-dev#6314)

* test: skip pytorch doc examples on platforms they don't support (prefix-dev#6317)

* fix(core): key locked records by declared platform for rich platforms (prefix-dev#6315)

* chore(ci): Update GitHub Actions to v6.0.3 (prefix-dev#6319)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(ci): Update Pixi to >=0.24,<0.25 (prefix-dev#6321)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* feat(pixi_spec): support extras, flags and when on conda dependencies (prefix-dev#6262)

* fix(satisfiability): detect extra-dependency drift for source packages (prefix-dev#6263)

* docs: add a pixi-build v3 example using extras, flags and when (prefix-dev#6264)

* fix(ci): Attest the tarballs and the binary inside separately (prefix-dev#6266)

* chore: bump pixi-build-api-version to 5 (prefix-dev#6328)

* ci: move doc examples to `pixi_build` (prefix-dev#6330)

* fix: stop requiring old backend version doc example (prefix-dev#6338)

* feat(test): Do not run tests un unsupported platforms

---------

Co-authored-by: Bas Zalmstra <[email protected]>
Co-authored-by: Tobias Hunger <[email protected]>
Co-authored-by: Ben Moss <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: nichmor <[email protected]>
Co-authored-by: Wolf Vollprecht <[email protected]>
Co-authored-by: Pavel Zwerschke <[email protected]>
Co-authored-by: Claude <[email protected]>
Co-authored-by: Ruben Arts <[email protected]>
Co-authored-by: Andreas Albert <[email protected]>
Co-authored-by: Lucas Colley <[email protected]>
Co-authored-by: Hofer-Julian <[email protected]>
Co-authored-by: jinhyuk9714 <[email protected]>
Co-authored-by: GitHub Actions <[email protected]>
Co-authored-by: Filippo Luca Ferretti <[email protected]>
Co-authored-by: samrosenf <[email protected]>
Co-authored-by: Ruben Arts <[email protected]>
Co-authored-by: jmayes-rx <[email protected]>
Co-authored-by: Suleman Karigar <[email protected]>
Co-authored-by: Tim de Jager <[email protected]>
Co-authored-by: Kevin Mills <[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.

2 participants