Skip to content

Index reinstalls when partitioning shared builds - #300

Draft
zaniebot wants to merge 3 commits into
mainfrom
zb/bughuntperf/282-build-reinstall-partition
Draft

zaniebot wants to merge 3 commits into
mainfrom
zb/bughuntperf/282-build-reinstall-partition

Conversation

@zaniebot

@zaniebot zaniebot commented Jul 16, 2026 •

Copy link
Copy Markdown
Collaborator

Partitioning an install plan into isolated and shared-build phases scans the shared-phase remote distributions for every reinstall. Large plans can repeat the same name comparisons quadratically. Build a borrowed-name index when there are more than eight shared-phase remotes and more than 32 reinstalls, initializing it only when a lookup does not match the first remote. Smaller plans and repeated first-name matches keep the allocation-free scan.

Hyperfine 2.0.0 measurements of 1f85ea101 → 7c5f51bf6 used release builds with Rust 1.99.0 and CPython 3.12.13 on an AMD EPYC-Genoa Linux VM, pinned to four CPUs. The command was uv pip install -r requirements.in --refresh --link-mode copy --no-index --find-links WHEELS --python VENV_PYTHON, with --no-config --color never --cache-dir CACHE. Output went to /dev/null.

Each invocation replaces synthetic installed 0.9.0 distributions with valid local 1.0.0 wheels. --no-build-isolation-package is repeated for each name selecting the shared installation phase. Hyperfine's --prepare restores the complete old installed tree outside measured time and RSS. Explicit refresh exercises preparation and phase partitioning with populated caches. Whole-command time includes resolution, planning, partitioning, wheel preparation, removal, copying, and metadata writes. OS pages and cache contents were warm, with refresh enabled. No source backend is executed.

Values are means, parent → head. Changes are (head / parent - 1) with 95% confidence intervals; negative values indicate a reduction.

Workload Wall time Change, 95% CI Peak RSS Change, 95% CI
1 replacement / 1 shared-phase name 70.4 → 70.1 ms -0.44% [-1.64%, +0.89%] 36.26 → 36.40 MiB +0.39% [-0.27%, +1.06%]
32 replacements / 1 shared-phase name 123.9 → 125.1 ms +1.00% [-0.68%, +3.35%] 41.50 → 41.80 MiB +0.72% [-0.16%, +1.63%]
32 replacements / 8 shared-phase names 123.4 → 122.3 ms -0.88% [-3.80%, +1.64%] 41.33 → 41.46 MiB +0.30% [-0.22%, +0.85%]
33 replacements / 9 shared-phase names 124.3 → 122.9 ms -1.15% [-2.58%, +0.10%] 41.60 → 41.58 MiB -0.04% [-0.76%, +0.65%]
1,024 replacements / 0 shared-phase names 1,694.4 → 1,694.9 ms +0.03% [-1.54%, +1.70%] 115.65 → 117.88 MiB +1.93% [-2.71%, +7.08%]
1,024 replacements / 1 shared-phase name 1,677.5 → 1,685.1 ms +0.45% [-1.68%, +2.76%] 114.92 → 116.67 MiB +1.52% [-7.14%, +13.24%]
1,024 replacements / 512 shared-phase names 1,669.0 → 1,664.9 ms -0.24% [-1.36%, +0.95%] 117.08 → 113.16 MiB -3.35% [-5.63%, -1.18%]
2,048 replacements / 1,024 shared-phase names 3,164.3 → 3,166.0 ms +0.05% [-0.68%, +0.63%] 148.59 → 146.43 MiB -1.45% [-5.37%, +3.37%]

Each workload used ten comparison blocks with alternating revision order, one warmup followed by three measured runs per revision in each block (30 measurements per revision). The pointwise 95% percentile-bootstrap intervals use 20,000 resamples of paired block means and retain all samples. They estimate within-run uncertainty, not variation across machines, independent builds, or separate benchmark campaigns.

All eight runtime intervals include zero. The largest replacement plan changes from 3,164.3 ms to 3,166.0 ms, or +0.05% [-0.68%, +0.63%]. The 1,024-replacement, 512-shared-name case uses about 3.92 MiB less peak RSS: 117.08 MiB before and 113.16 MiB after, a reduction of 3.35% with a change interval of -5.63% to -1.18%. The other seven RSS intervals include zero. These complete replacement commands show a memory reduction in one indexed workload without an established runtime improvement. RSS is Hyperfine's Linux wait4 peak, not an allocation count or summed simultaneous process-tree memory.

Existing component benchmarks

Add Plan::partition benchmarks for small and large mixed plans, asymmetric remote/reinstall counts, and first-hit, last-hit, and missing-name cases. The linear comparison is a reduced copy of the previous membership loop.

@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/bughuntperf/282-build-reinstall-partition branch from 813465e to e28a809 Compare August 11, 2026 18:08
@zaniebot zaniebot added priority:3 Normal: useful features, documentation, usability, or routine efficiency improvements. size:2 Moderate: one subsystem with meaningful invariants, edge cases, or operational evidence to inspect. performance risk:1 Negligible risk of localized mistakes that are obvious and easy to correct. labels Sep 9, 2026
@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/bughuntperf/282-build-reinstall-partition branch from e28a809 to 1ce6234 Compare October 1, 2026 22:32
@codspeed

codspeed Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ 8 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 54 untouched benchmarks
🆕 32 new benchmarks
⏩ 35 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
🆕 Simulation indexed[asymmetric-16x4096] N/A 10.7 ms N/A
🆕 Simulation indexed[asymmetric-4096x16] N/A 2.4 ms N/A
🆕 Simulation indexed[asymmetric-4096x32] N/A 4 ms N/A
🆕 Simulation indexed[asymmetric-4096x8] N/A 1.6 ms N/A
🆕 Simulation indexed[asymmetric-8x4096] N/A 11 ms N/A
🆕 Simulation indexed[hit-first-4096x4096] N/A 9.2 ms N/A
🆕 Simulation indexed[hit-last-4096x4096] N/A 8.1 ms N/A
🆕 Simulation indexed[miss-4096x4096] N/A 7.9 ms N/A
🆕 Simulation indexed[mixed-1024x1024] N/A 3.8 ms N/A
🆕 Simulation indexed[mixed-128x128] N/A 434.1 µs N/A
🆕 Simulation indexed[mixed-16x16] N/A 43.3 µs N/A
🆕 Simulation indexed[mixed-32x32] N/A 89.8 µs N/A
🆕 Simulation indexed[mixed-4096x4096] N/A 12.3 ms N/A
🆕 Simulation indexed[mixed-512x512] N/A 1.8 ms N/A
🆕 Simulation indexed[mixed-64x64] N/A 149.1 µs N/A
🆕 Simulation indexed[mixed-8x8] N/A 22.3 µs N/A
🆕 Simulation linear[asymmetric-16x4096] N/A 12.4 ms N/A
🆕 Simulation linear[asymmetric-4096x16] N/A 2.4 ms N/A
🆕 Simulation linear[asymmetric-4096x32] N/A 3.9 ms N/A
🆕 Simulation linear[asymmetric-4096x8] N/A 1.6 ms N/A
... ... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.


Comparing zb/bughuntperf/282-build-reinstall-partition (7c5f51b) with main (238d6ba)

Open in CodSpeed

Footnotes

  1. 35 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@zaniebot zaniebot added the build:skip-release Disable building release binaries for a pull request label Oct 7, 2026
@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/bughuntperf/282-build-reinstall-partition branch from 1ce6234 to 27ec7d3 Compare October 7, 2026 23:17
Comment on lines +89 to +92
let right_remote = remote;
let (left_reinstalls, right_reinstalls) = reinstalls
.into_iter()
.partition::<Vec<_>, _>(|dist| !right_remote.iter().any(|d| d.name() == dist.name()));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P3] Compare equivalent partition operations

The linear baseline moves remote directly, while Plan::partition first runs remote.into_iter().partition(...). Consequently, the small and asymmetric cases compare different work even when should_index is false and both use the same membership scan. This confounds the comparison intended to justify the indexing thresholds. Include the same remote partition in the baseline, or compare the production benchmark across base and head.

Comment on lines +153 to +157
group.bench_function(BenchmarkId::new("linear", &input), |benchmark| {
benchmark.iter(|| partition_linear(black_box(plan(&remote, &reinstalls))));
});
group.bench_function(BenchmarkId::new("indexed", &input), |benchmark| {
benchmark.iter(|| black_box(plan(&remote, &reinstalls)).partition(|_| false));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P3] Move fixture cloning outside the timed loop

Both timed closures call plan, which clones every remote Arc and every InstalledDist, including its boxed installation path. Production partitioning consumes an existing plan without these clones. Including this additional linear work and result destruction dilutes the lookup cost, particularly for the small cases used to assess the cutoffs. Use iter_batched with plan(...) in the setup closure and return the partition result from the measured closure, following the existing benchmark patterns.

@zaniebot
zaniebot deployed to automations October 8, 2026 23:16 — with GitHub Actions Active
@zaniebot
zaniebot deployed to automations October 8, 2026 23:19 — with GitHub Actions Active
Comment on lines +1 to +3
//! Benchmarks for separating reinstalls between isolated and shared source-build phases.

use std::hint::black_box;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P3] Use uv's allocator in the partition benchmark

This benchmark never references uv_performance_memory_allocator, so it uses the system allocator on targets where uv normally selects jemalloc or mimalloc. The optimization trades linear scans for an allocated FxHashSet, making allocator costs relevant to the small-plan indexing thresholds. Add extern crate uv_performance_memory_allocator;, following benches/uv.rs and workspace_discovery.rs, so the measurements reflect uv's allocator.

@zaniebot
zaniebot deployed to automations October 9, 2026 16:15 — with GitHub Actions Active
@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/bughuntperf/282-build-reinstall-partition branch from 7c5f51b to 94c39b2 Compare October 18, 2026 03:56
@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/bughuntperf/282-build-reinstall-partition branch from 94c39b2 to 1314e29 Compare October 23, 2026 19:13

This branch was successfully deployed

1 active (outdated) deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build:skip-release Disable building release binaries for a pull request performance priority:3 Normal: useful features, documentation, usability, or routine efficiency improvements. risk:1 Negligible risk of localized mistakes that are obvious and easy to correct. size:2 Moderate: one subsystem with meaningful invariants, edge cases, or operational evidence to inspect.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants