Skip to content

Avoid DNF expansion when resolving activated extras - #256

Draft
zaniebot wants to merge 1 commit into
mainfrom
zb/bughuntperf/232-activated-extra-bdd
Draft

zaniebot wants to merge 1 commit into
mainfrom
zb/bughuntperf/232-activated-extra-bdd

Conversation

@zaniebot

@zaniebot zaniebot commented Jul 16, 2026 •

Copy link
Copy Markdown
Collaborator

Requirements-txt export resolves activated extras in dependency markers. Expanding a wide marker into disjunctive normal form can create many clauses, while resolving each generated extra by scanning and re-encoding the known conflicts repeats work across graph edges.

Resolve markers with more than eight distinct extras directly in the BDD, and keep the DNF path for small markers. The small-marker path decodes generated extra, group, and project names for direct conflict lookup. The wide-marker path indexes the needed encoded conflicts once and substitutes extras in variable order, with canonical range coalescing so downstream reachability can converge. Markers without extras return unchanged.

Hyperfine 2.0.0 measurements of 1bf677913 → 28608af11 used release builds of the complete CLI with rustc 1.99.0 (b940084d7 2026-09-28) on an AMD EPYC-Genoa Linux VM, pinned to four CPUs. Output went to /dev/null. The supplied interpreter was CPython 3.12.13.

Each uv export --frozen --no-emit-workspace command reads a synthetic, parent-generated workspace lock and formats requirements. The member declares extras that request shared wheel dependencies; conflict cases declare those extras mutually exclusive. Conditional cases export the root, which requests extra-000 below Python 3.13 and extra-001 at or above 3.13. The constant case exports the member with --extra extra-000. A no-conflict case uses the same declared-extra shape.

The table counts declared member extras and shared and common wheel names. Input locks contain markers with up to 4–50 distinct extra names in the conflict cases; the no-conflict control has at most one per input marker. The widths describe input-lock markers, not measured helper inputs; no retained runtime trace establishes whether an export enters the greater-than-eight-extra path. Each complete command includes lock parsing, dependency-graph construction and requirements formatting. Each command starts a fresh process with warm OS pages, local wheel metadata and interpreter-query caches. The parent-generated lock is unchanged between invocations; no package installation or source build runs.

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
4 declared extras / 1 shared wheel / 1 common wheel / conditional / conflicts 17.2 → 17.3 ms +0.61% [-0.89%, +1.90%] 26.85 → 26.72 MiB -0.47% [-0.84%, -0.09%]
8 declared extras / 1 shared wheel / 1 common wheel / conditional / conflicts 19.0 → 19.2 ms +0.73% [-0.99%, +2.49%] 27.34 → 27.25 MiB -0.34% [-0.70%, +0.03%]
9 declared extras / 1 shared wheel / 1 common wheel / conditional / conflicts 20.7 → 19.0 ms -8.07% [-9.13%, -6.94%] 27.33 → 27.72 MiB +1.40% [+1.03%, +1.77%]
16 declared extras / 1 shared wheel / 1 common wheel / conditional / conflicts 83.2 → 25.1 ms -69.84% [-72.50%, -65.19%] 28.58 → 29.55 MiB +3.37% [+3.05%, +3.72%]
30 declared extras / 1 shared wheel / 1 common wheel / conditional / conflicts 2,183.6 → 37.4 ms -98.29% [-98.32%, -98.25%] 37.30 → 37.16 MiB -0.38% [-0.89%, +0.11%]
50 declared extras / 1 shared wheel / 1 common wheel / conditional / conflicts 38,910.1 → 95.7 ms -99.75% [-99.76%, -99.74%] 73.56 → 73.47 MiB -0.12% [-0.32%, +0.06%]
50 declared extras / 1 shared wheel / 1 common wheel / constant / conflicts 5,962.2 → 92.3 ms -98.45% [-98.48%, -98.43%] 73.63 → 73.42 MiB -0.29% [-0.45%, -0.12%]
16 declared extras / 16 shared wheels / 32 common wheels / conditional / conflicts 603.1 → 32.7 ms -94.57% [-94.64%, -94.51%] 29.87 → 30.55 MiB +2.26% [+1.86%, +2.69%]
16 declared extras / 16 shared wheels / 32 common wheels / conditional / no conflicts 18.4 → 18.4 ms +0.07% [-1.56%, +1.56%] 27.25 → 27.32 MiB +0.28% [-0.03%, +0.61%]

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.

Six conflict-case runtime intervals show reductions, including the constant-member export; the four-extra, eight-extra, and no-conflict intervals include zero. RSS increased in the nine-extra and both 16-extra conflict cases, by 1.40%, 3.37%, and 2.26%, respectively; two RSS intervals show reductions and four include zero. These results cover whole exports. RSS is Hyperfine's Linux wait4 peak, not an allocation count or summed simultaneous process-tree memory.

Earlier measurements

Earlier standalone algorithm-model size sweeps used a different source and toolchain context. They did not establish source-matched component or whole-export confidence intervals for 1bf67791 → 28608af1.

@zaniebot
zaniebot force-pushed the zb/bughuntperf/232-activated-extra-bdd branch from e1ee524 to b402b93 Compare July 16, 2026 04:59
@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/bughuntperf/232-activated-extra-bdd branch from b402b93 to 7bb2083 Compare July 27, 2026 20:27
@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 preview Experimental behavior risk:3 Credible risk of meaningful incorrect behavior or regression; bounded or recoverable. labels Sep 9, 2026
@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/bughuntperf/232-activated-extra-bdd branch from 7bb2083 to 28608af Compare September 16, 2026 13:05
@codspeed

codspeed Bot commented Sep 16, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 25 untouched benchmarks


Comparing zb/bughuntperf/232-activated-extra-bdd (28608af) with main (f67344d)

Open in CodSpeed

@zaniebot zaniebot added priority:3 Normal: useful features, documentation, usability, or routine efficiency improvements. size:3 Substantial: interacting behaviors, difficult compatibility questions, or a careful migration. and removed 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. labels Oct 11, 2026
@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/bughuntperf/232-activated-extra-bdd branch from 28608af to 906f5d1 Compare October 17, 2026 18:13
Comment on lines +807 to +809
let (len, tail) = tail.split_once('-')?;
let len = len.parse::<usize>().ok()?;
let (package, tail) = tail.split_at_checked(len)?;

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] Reject zero-padded lengths when decoding conflict names

parse::<usize>() accepts 03, so extra-03-pkg-foo now resolves to the activation of pkg[foo]. However, the encoder produces only extra-3-pkg-foo: both the previous implementation and the BDD path treat the zero-padded spelling as a literal package extra. With foo selected and the literal extra inactive, the small-marker path can therefore include an unwanted dependency. Reject noncanonical length prefixes before lookup and cover this spelling in the encoded-looking-extra tests.

Comment on lines +865 to +867
marker.visit_extras(|_, extra| {
if !extras.is_empty() {
extras.insert(extra.clone());

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] Preserve shared subgraphs during BDD traversal

visit_extras recursively visits both children without tracking visited nodes; deduplicating names in this callback does not deduplicate traversal. A conjunction of disjunctions with adjacent variable names, such as (extra == 'e00a' or extra == 'e00b') and ..., has a linear-size BDD but exponentially many traversal paths. The restrict_by implementation used by the substitutions also revisits shared children. Thus this path avoids DNF allocation while retaining exponential work on compact markers. Use memoized node traversal for discovery and restriction/substitution, and exercise this shared-subgraph shape.

Comment on lines +945 to +947
// Substitute extras in BDD variable order. Restricting a later variable before an earlier one
// can leave adjacent version/string ranges pointing at the same child, which is semantically
// equivalent but not canonical and can prevent downstream reachability from converging.

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 canonicalization ordering claim

Edges::map already calls map_ranges, which coalesces adjacent ranges after restriction. The newly added simplify_extras_preserves_canonical_ranges test also explicitly checks both substitution orders. This comment incorrectly makes canonicalization and convergence appear to depend on caller ordering, obscuring the guarantee owned by the marker implementation. Remove that claim; if sorting remains useful for deterministic execution or performance, document that rationale instead.

@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/bughuntperf/232-activated-extra-bdd branch from 906f5d1 to 00d41cb Compare October 18, 2026 10:34

This branch had an error being deployed

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

Labels

performance preview Experimental behavior priority:3 Normal: useful features, documentation, usability, or routine efficiency improvements. risk:3 Credible risk of meaningful incorrect behavior or regression; bounded or recoverable. 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