Skip to content

Batch project dependency additions - #270

Draft
zaniebot wants to merge 4 commits into
mainfrom
zb/bughuntperf/244-batch-add
Draft

zaniebot wants to merge 4 commits into
mainfrom
zb/bughuntperf/244-batch-add

Conversation

@zaniebot

@zaniebot zaniebot commented Jul 16, 2026 •

Copy link
Copy Markdown
Collaborator

Adding a large requirements file with uv add reparses, rescans, and reformats the complete dependency array for every requirement, then repeatedly shifts prior edit offsets. Batch additions to uncommented dependency arrays, updating existing entries and sources in one pass while preserving their order. Mixed or commented arrays keep the existing item-at-a-time path.

Development additions also scan unrelated dependency tables for every input. Check only the standardized and legacy development tables, preserving their existing precedence and fallback.

Hyperfine 2.0.0 measurements of 00e49e7e7 → c26a6af13 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 add --raw --requirements INPUT --frozen --python PYTHON --directory FIXTURE --offline --no-config --color never --cache-dir CACHE, adding --dev for development cases. OS page caches were warm and output went to /dev/null.

Production cases add N new requirements to N existing requirements. Development cases add N requirements to an empty development group while the project has N production dependencies, N optional extras, and N unrelated groups. All requirements explicitly pin ==1.0.0. The commented-array case uses the fallback path. Hyperfine's --prepare restores the root pyproject.toml before each invocation; restoration is excluded from time and peak RSS. Frozen edits do not resolve dependencies or synchronize an environment. These are synthetic project-edit workloads.

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
Add 32 production requirements to 32 existing 19.1 → 20.1 ms +5.39% [-8.20%, +26.41%] 26.63 → 26.46 MiB -0.66% [-0.94%, -0.34%]
Add 128 production requirements to 128 existing 25.4 → 17.5 ms -30.92% [-31.89%, -29.97%] 26.92 → 26.87 MiB -0.22% [-0.65%, +0.28%]
Add 512 production requirements to 512 existing 138.5 → 19.8 ms -85.73% [-86.04%, -85.43%] 27.68 → 27.81 MiB +0.45% [+0.24%, +0.66%]
Add 2,048 production requirements to 2,048 existing 1,882.6 → 27.9 ms -98.52% [-98.55%, -98.49%] 31.28 → 32.96 MiB +5.35% [+4.92%, +5.75%]
Add 128 development requirements, 128 extras and 128 unrelated groups 34.5 → 18.7 ms -45.97% [-46.67%, -45.29%] 27.66 → 27.42 MiB -0.87% [-1.20%, -0.54%]
Add 512 development requirements, 512 extras and 512 unrelated groups 259.1 → 22.8 ms -91.22% [-91.36%, -91.06%] 29.92 → 29.72 MiB -0.67% [-0.95%, -0.39%]
Add 512 production requirements to a commented 512-item array 138.9 → 139.6 ms +0.53% [-1.79%, +2.65%] 27.78 → 27.98 MiB +0.75% [+0.42%, +1.08%]

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 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.

The 128-, 512-, and 2,048-requirement production cases reduce mean wall time by 31%, 86%, and 98.5%, respectively. Development additions reduce it by 46–91%. The smallest production case and the commented-array fallback have runtime intervals that include zero. Peak RSS changes are small compared with the runtime changes: the largest production case increases by about 1.68 MiB (5.4%), while other mean RSS differences are at most 0.24 MiB. These whole-command measurements include startup, requirements parsing, project discovery, editing, formatting, and filesystem writes. RSS is Hyperfine's Linux wait4 peak, not an allocation count or summed simultaneous process-tree memory.

@zaniebot zaniebot added the build:skip-docker Skip Docker builds for this pull request label Jul 16, 2026
@zaniebot zaniebot closed this Jul 16, 2026
@zaniebot zaniebot reopened this Jul 16, 2026
@zaniebot
zaniebot force-pushed the zb/bughuntperf/244-batch-add branch 4 times, most recently from b1faf97 to e7bfe4c Compare July 16, 2026 07:44
@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/bughuntperf/244-batch-add branch from e7bfe4c to 0b628e6 Compare July 22, 2026 14:14
@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/bughuntperf/244-batch-add branch from 0b628e6 to 7ad6323 Compare July 30, 2026 15:34
@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/bughuntperf/244-batch-add branch from 7ad6323 to 9b85da4 Compare August 11, 2026 17:23
@zaniebot zaniebot added priority:2 Important: bounded correctness, release reliability, committed work, or proven performance gains. size:3 Substantial: interacting behaviors, difficult compatibility questions, or a careful migration. 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/244-batch-add branch from 9b85da4 to 219bcb7 Compare October 1, 2026 22:50
@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
🆕 17 new benchmarks
⏩ 35 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
🆕 Simulation project dependency additions with sources/128 N/A 5.7 ms N/A
🆕 Simulation project dependency additions with sources/2048 N/A 87.2 ms N/A
🆕 Simulation project dependency additions with sources/512 N/A 23.1 ms N/A
🆕 Simulation project dependency additions/128 N/A 2 ms N/A
🆕 Simulation project dependency additions/2048 N/A 28.6 ms N/A
🆕 Simulation project dependency additions/512 N/A 7.9 ms N/A
🆕 Simulation project dependency marker updates/128 N/A 3.1 ms N/A
🆕 Simulation project dependency marker updates/2048 N/A 59.2 ms N/A
🆕 Simulation project dependency marker updates/512 N/A 13.3 ms N/A
🆕 Simulation project dependency updates/128 N/A 1.5 ms N/A
🆕 Simulation project dependency updates/2048 N/A 22.3 ms N/A
🆕 Simulation project dependency updates/512 N/A 5.5 ms N/A
🆕 Simulation project dev dependency lookup indexed/128 N/A 815.9 µs N/A
🆕 Simulation project dev dependency lookup indexed/2048 N/A 13 ms N/A
🆕 Simulation project dev dependency lookup indexed/512 N/A 3.3 ms N/A
🆕 Simulation project dev dependency lookup linear/128 N/A 223.2 ms N/A
🆕 Simulation project dev dependency lookup linear/512 N/A 3.6 s N/A

Comparing zb/bughuntperf/244-batch-add (c26a6af) with main (1a2544a)2

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. ↩

  2. No successful run was found on main (0e23f06) during the generation of this report, so 1a2544a was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@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/244-batch-add branch 2 times, most recently from 3fa0487 to 98bb1c7 Compare October 8, 2026 03:41
Comment on lines +1730 to +1732
/// Determine the ordering of the string entries in a dependency array.
fn dependency_sort(deps: &Array) -> DependencySort {
fn is_sorted<T, I>(items: I) -> bool

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] Share the sorting policy with the fallback path

The new DependencySort, detection logic, and comparator duplicate the sorting policy inside add_dependency, which remains the production fallback for commented and mixed batches. Changes to case sensitivity or specifier ordering now require coordinated updates to both implementations. Have add_dependency use dependency_sort and compare_dependencies too, while still recalculating the sort before each insertion so mixed batches retain their behavior.

Comment thread crates/uv-project-edit/src/lib.rs Outdated
Comment on lines +699 to +703
let dependencies = match dependency_type {
DependencyType::Production => self
.project()?
.entry("dependencies")
.or_insert(Item::Value(Value::Array(Array::new())))

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] Reuse the existing dependency-array accessors

These branches repeat dependencies_array, dev_dependencies_array, optional_dependencies_array, and dependency_groups_array, already used by set_dependency_bound. Additions and subsequent bound updates must resolve the same normalized keys and validate the same table shapes; duplicating that logic creates another place to maintain those rules. Delegate the four branches to those accessors, retaining the batch-specific sorting and formatting around the call.

@zaniebot
zaniebot deployed to automations October 9, 2026 00:24 — with GitHub Actions Active
@zaniebot
zaniebot deployed to automations October 9, 2026 00:28 — with GitHub Actions Active
Comment thread crates/uv-project-edit/src/lib.rs Outdated
Comment on lines +665 to +668
pub fn add_dependencies(
&mut self,
dependency_type: &DependencyType,
requirements: &[(&Requirement, Option<&Source>)],

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] Keep cross-array batching inside the editor API

Interleaved legacy and standardized development additions require grouping array edits while applying sources in original input order, as batch_add_preserves_interleaved_source_order demonstrates. This batch API accepts only one dependency type, so its production caller must bypass it, coordinate both lower-level methods, and replace placeholder edit indices. That leaves the ordering contract in command-specific code. Accept a dependency type per request and encapsulate grouping and source application here, returning edits in input order; the two phases can then remain private.

Comment thread crates/uv/tests/project/edit.rs Outdated
Comment on lines +4472 to +4475
let production = (0..128)
.map(|index| format!(" \"production-{index:04}>=1\","))
.collect::<Vec<_>>()
.join("\n");

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 a smaller snapshot fixture for development routing

The generated 128-entry tables and batches do not verify that repeated scanning was eliminated: these output assertions also pass with the original scanning implementation. Their size leads to manual TOML extraction and numeric offsets, which omit formatting and unrelated-table changes from verification. Keep scale coverage in the accompanying benchmark, use a few explicit dependencies here, and snapshot the complete pyproject.toml after each command, following nearby add_batch_dev_dependency_bounds and the existing development-routing tests.

@zaniebot
zaniebot deployed to automations October 9, 2026 18:34 — with GitHub Actions Active
@zaniebot
zaniebot deployed to automations October 9, 2026 18:39 — with GitHub Actions Active
Comment thread crates/uv-project-edit/src/lib.rs Outdated
Comment on lines +1704 to +1705
let matches = existing.get(&key).into_iter().flatten().collect::<Vec<_>>();
if matches.len() > 1 {

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] Borrow the indexed matches instead of collecting another vector

existing.get(&key) already provides the matching entries, but this collects their references into another vector just to inspect its length and emptiness. Update batches incur an avoidable allocation for each matched requirement. Borrow the existing vector as a slice, using an empty slice for absent keys, and allocate the diagnostic requirements only in the ambiguous case.

Comment on lines +1 to +3
//! Benchmarks for applying large batches of direct project-dependency edits.

use std::fmt::Write;

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] Link uv's allocator into the new benchmark

This benchmark does not reference uv_performance_memory_allocator, so ordinary wall-time runs use the system allocator instead of uv's default jemalloc/mimalloc. Allocator choice matters for these allocation-heavy parsing and editing workloads. Add extern crate uv_performance_memory_allocator; following workspace_discovery.rs and uv_pypi_types.rs; the dependency is already declared.

@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/bughuntperf/244-batch-add branch from b9b774a to 3580338 Compare October 23, 2026 19:23
Comment on lines +595 to +596
#[cfg(test)]
fn add_dependency_group_requirement(

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] Remove the obsolete editor methods retained as test oracles

The four former single-dependency methods now exist only to generate expected results for the new parity tests. They retain separate table creation, normalized-key lookup, and group formatting logic alongside the production array accessors and add_dependency_array, requiring future changes to maintain a second editor implementation. Assert explicit TOML snapshots and final ArrayEdit values through add_dependencies, then remove these test-only methods. The free add_dependency function remains justified by the production fallback.

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-docker Skip Docker builds for this pull request build:skip-release Disable building release binaries for a pull request performance priority:2 Important: bounded correctness, release reliability, committed work, or proven performance gains. risk:1 Negligible risk of localized mistakes that are obvious and easy to correct. size:3 Substantial: interacting behaviors, difficult compatibility questions, or a careful migration.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants