Repository navigation
Conversation
b1faf97 to
e7bfe4c
Compare
e7bfe4c to
0b628e6
Compare
0b628e6 to
7ad6323
Compare
7ad6323 to
9b85da4
Compare
9b85da4 to
219bcb7
Compare
Merging this PR will not alter performance
|
3fa0487 to
98bb1c7
Compare
| /// 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 |
There was a problem hiding this comment.
[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.
| let dependencies = match dependency_type { | ||
| DependencyType::Production => self | ||
| .project()? | ||
| .entry("dependencies") | ||
| .or_insert(Item::Value(Value::Array(Array::new()))) |
There was a problem hiding this comment.
[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.
| pub fn add_dependencies( | ||
| &mut self, | ||
| dependency_type: &DependencyType, | ||
| requirements: &[(&Requirement, Option<&Source>)], |
There was a problem hiding this comment.
[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.
| let production = (0..128) | ||
| .map(|index| format!(" \"production-{index:04}>=1\",")) | ||
| .collect::<Vec<_>>() | ||
| .join("\n"); |
There was a problem hiding this comment.
[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.
| let matches = existing.get(&key).into_iter().flatten().collect::<Vec<_>>(); | ||
| if matches.len() > 1 { |
There was a problem hiding this comment.
[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.
| //! Benchmarks for applying large batches of direct project-dependency edits. | ||
|
|
||
| use std::fmt::Write; |
There was a problem hiding this comment.
[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.
c26a6af to
b9b774a
Compare
b9b774a to
3580338
Compare
| #[cfg(test)] | ||
| fn add_dependency_group_requirement( |
There was a problem hiding this comment.
[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.
Adding a large requirements file with
uv addreparses, 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--devfor 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--preparerestores the rootpyproject.tomlbefore 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.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
wait4peak, not an allocation count or summed simultaneous process-tree memory.