Skip to content

Avoid DNF expansion for conflict environments - #253

Draft
zaniebot wants to merge 3 commits into
mainfrom
zb/bughuntperf/230-conflict-environment-bdd
Draft

zaniebot wants to merge 3 commits into
mainfrom
zb/bughuntperf/230-conflict-environment-bdd

Conversation

@zaniebot

@zaniebot zaniebot commented Jul 16, 2026 •

Copy link
Copy Markdown
Collaborator

Validating conflicts for a selected locked dependency subgraph restricts mixed environment and conflict markers to the active Python environment. Expanding those markers to DNF first can enumerate many alternatives even when only one environment branch applies. Have UniversalMarker::conflict_for_environment follow the decision diagram directly, memoize shared subtrees, and retain the extra decisions needed for conflict selection. The traversal handles complemented edges, evaluates PEP 751 list markers with empty extras and dependency groups, and retains the lexicographic marker-warning path. For an input of MarkerTree::TRUE, the resulting conflict marker now remains true instead of becoming false.

The PR also adds a separate CodSpeed-compatible benchmark for MarkerTree::only_extras_for_environment, using 16, 64, or 256 synthetic platform/extra alternatives. Its helper clock excludes construction of those inputs.

Hyperfine 2.0.0 measurements of 6a7747355 → 996a81eed used identical production API drivers built in release mode with rustc 1.99.0 (b940084d7 2026-09-28) on an AMD EPYC-Genoa Linux VM, pinned to four CPUs. The measured base is the merge base before three commits; the comparison includes their combined production changes and does not isolate the final commit. Output went to /dev/null.

Each fresh uv-hyperfine-marker component process restricts synthetic UniversalMarker inputs to a fixed environment with conflict_for_environment; it does not invoke the uv CLI. The inputs combine platform and extra alternatives, vary the matching input position, include a miss and a complemented marker, and include a pure-extra control. First and last refer to input construction position, not established decision-diagram traversal order. One case makes a single call; the others make 1,000 calls per process. The constant MarkerTree::TRUE input is outside these workloads.

Argument parsing, marker and environment construction, the API calls, output and teardown are included. Repeated calls within one process are not independent samples. These workloads do not measure a complete uv command. Each process uses the production allocator and warm OS pages. Peak RSS includes input construction and API scratch memory; it is not an allocation count or a helper-only memory delta. No network operation occurs.

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

Workload Wall time Change, 95% CI Peak RSS Change, 95% CI
1 alternative / first input alternative matches / 1,000 calls 4.7 → 4.1 ms -11.92% [-14.72%, -9.07%] 3.22 → 3.22 MiB +0.00% [+0.00%, +0.00%]
16 alternatives / first input alternative matches / 1,000 calls 23.7 → 4.3 ms -81.85% [-82.21%, -81.48%] 3.22 → 3.22 MiB +0.00% [+0.00%, +0.00%]
16 alternatives / last input alternative matches / 1,000 calls 23.9 → 4.7 ms -80.32% [-80.72%, -79.91%] 3.25 → 3.25 MiB +0.00% [+0.00%, +0.00%]
64 alternatives / last input alternative matches / 1,000 calls 216.2 → 6.5 ms -97.00% [-97.07%, -96.91%] 3.75 → 3.75 MiB +0.00% [+0.00%, +0.00%]
256 alternatives / first input alternative matches / 1,000 calls 2,964.3 → 18.6 ms -99.37% [-99.38%, -99.36%] 11.75 → 11.50 MiB -2.13% [-2.13%, -2.13%]
256 alternatives / last input alternative matches / 1,000 calls 2,974.4 → 22.2 ms -99.25% [-99.26%, -99.24%] 11.75 → 11.52 MiB -1.99% [-2.13%, -1.77%]
256 alternatives / no matching alternative / 1,000 calls 2,969.8 → 22.2 ms -99.25% [-99.26%, -99.24%] 11.75 → 11.51 MiB -2.06% [-2.13%, -1.91%]
64 alternatives / complemented marker / last input alternative matches / 1,000 calls 926.2 → 6.4 ms -99.31% [-99.32%, -99.30%] 3.75 → 3.75 MiB +0.00% [+0.00%, +0.00%]
0 alternatives / pure-extra control / 1,000 calls 4.2 → 4.1 ms -2.66% [-6.08%, +0.81%] 3.25 → 3.25 MiB +0.00% [+0.00%, +0.00%]
256 alternatives / last input alternative matches / 1 call 21.6 → 18.2 ms -15.72% [-16.97%, -14.53%] 11.75 → 11.51 MiB -2.06% [-2.13%, -1.91%]

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.

Nine runtime intervals show reductions; the pure-extra control interval includes zero. Four RSS intervals show reductions, and the other six are exactly zero. For the 256-alternative first-input case, every RSS observation was identical within each arm, producing coincident interval endpoints. RSS is Hyperfine's Linux wait4 peak, not an allocation count or summed simultaneous process-tree memory. For very small processes, an inherited startup peak from Hyperfine can impose a floor on reported RSS.

@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
@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/bughuntperf/230-conflict-environment-bdd branch from 9ea8a81 to 8e7b0da Compare July 27, 2026 20:24
@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/bughuntperf/230-conflict-environment-bdd branch from 8e7b0da to 054fce3 Compare August 11, 2026 17:46
@zaniebot zaniebot added priority:2 Important: bounded correctness, release reliability, committed work, or proven performance gains. size:4 Complex: architectural or security-sensitive work requiring broad or cross-repository context. 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/230-conflict-environment-bdd branch from 054fce3 to 92d7d9b Compare September 16, 2026 13:09
@codspeed

codspeed Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 12.61%

⚠️ 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

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 2 improved benchmarks
✅ 67 untouched benchmarks
🆕 3 new benchmarks
⏩ 35 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ Simulation from_hex/uppercase[48] 341 µs 295.9 µs +15.27%
⚡ ⚠️ Simulation discover_workspace_from_all_members 152.6 ms 138.7 ms +10.02%
🆕 Simulation bdd[16] N/A 11 µs N/A
🆕 Simulation bdd[256] N/A 11 µs N/A
🆕 Simulation bdd[64] N/A 11 µs N/A

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing zb/bughuntperf/230-conflict-environment-bdd (996a81e) with main (5a94b66)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 (725b74b) during the generation of this report, so 5a94b66 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/bughuntperf/230-conflict-environment-bdd branch from 92d7d9b to de18405 Compare October 1, 2026 23:04
@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/230-conflict-environment-bdd branch 2 times, most recently from 4fe0965 to e5fab1f Compare October 8, 2026 03:37
Comment thread crates/uv-pep508/src/marker/algebra.rs Outdated
});
self.create_node(node.var.clone(), children)
}
_ => NodeId::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.

[P2] Handle VersionString nodes explicitly

This fallback also matches legitimate Variable::VersionString nodes, which the constructor creates for Darwin platform_release comparisons. On Darwin with release 24.10.0, platform_release >= '24' and extra == 'foo' therefore becomes FALSE instead of retaining the extra condition. Consequently, conflict validation can accept an unresolved outside-subgraph conflict because the result appears constant. Handle VersionString using the parsing and range-selection semantics in evaluate_reporter_impl, add a Darwin regression case, and match variable variants exhaustively so omissions cannot silently become false.

Comment thread crates/uv-pep508/src/marker/tree.rs Outdated
marker.only_extras_for_environment(&env),
m("extra == 'foo'")
);
logs_contain("Comparing 10 and 2 lexicographically");

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] Assert that the warning was emitted

logs_contain returns a boolean, but this test discards it. Removing the new warning-reporting calls would therefore leave the warning regression test passing. Assert the result or use logs_assert, as the nearby warnings4 test does, so the test actually protects the diagnostic behavior.

@zaniebot
zaniebot deployed to automations October 8, 2026 23:24 — with GitHub Actions Active
@zaniebot
zaniebot deployed to automations October 8, 2026 23:28 — with GitHub Actions Active
Comment thread crates/uv-pep508/src/marker/algebra.rs Outdated
Comment on lines +801 to +805
(Variable::String(key), Edges::String { edges }) => {
let value = env.get_string(*key);
edges
.iter()
.find_map(|(range, child)| {

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 environment-node evaluation between the traversals

This traversal duplicates the environment decisions in MarkerTree::evaluate_reporter_impl, including version parsing, string comparisons, and lexicographic warnings. Dependency evaluation and conflict validation must interpret these expressions identically, but semantic or diagnostic changes now require coordinated edits in two modules. Extract the common environment-child selection into a private helper, keeping memoization and extra-node reconstruction specific to this traversal.

Comment on lines +34 to +36
group.bench_function(BenchmarkId::new("bdd", alternatives), |benchmark| {
benchmark
.iter(|| black_box(marker).only_extras_for_environment(black_box(&environment)));

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] Benchmark the existing conflict_for_environment entry point

Timing only the newly added helper prevents running this benchmark against the base implementation; restoring DNF expansion in conflict_for_environment would also leave these measurements unchanged. Construct uv_resolver::UniversalMarker::from_combined(marker) outside the timed loop and benchmark conflict_for_environment instead. uv-bench already depends on uv-resolver, so this retains the focused component measurement while enabling comparison across revisions and covering the optimized production call path.

@zaniebot
zaniebot deployed to automations October 9, 2026 16:36 — with GitHub Actions Active
@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/bughuntperf/230-conflict-environment-bdd branch from 424b7e9 to 996a81e Compare October 14, 2026 17:22
@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/bughuntperf/230-conflict-environment-bdd branch from 996a81e to 37584da Compare October 18, 2026 12:09

This branch was successfully deployed

1 active 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:4 Complex: architectural or security-sensitive work requiring broad or cross-repository context.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants