Skip to content

Speed up uv lock with large conflict sets - #22460

Closed
Samoed wants to merge 4 commits into
astral-sh:mainfrom
Samoed:optimize
Closed

Samoed wants to merge 4 commits into
astral-sh:mainfrom
Samoed:optimize

Conversation

@Samoed

@Samoed Samoed commented Oct 10, 2026 •

Copy link
Copy Markdown

Summary

With many conflicting extras, environment-dependent edges get a marker with a clause for every pair of extras. Converting these markers to DNF dominated uv lock and uv export, because simplification compared every pair of clauses term by term.

Simplification for expressions with 8 or more clauses, terms are interned and clauses compared as bit sets. For each clause, every other clause is compared once to find the terms it is missing. A term can only be removed using a clause whose missing terms are all negations of that term, so clauses missing more terms than the most negations any term has (in practice, one) are discarded up front. The remaining candidates are checked for each term and updated as terms are removed. The result is identical to the existing algorithm, which still handles smaller expressions.

Closes #21954
Closes #18317

Related:

This pr take some parts from:

Test Plan

Timings with the profiling profile, offline with a warm cache:

Scenario Before After
Issue reproduction, 50 extras, uv lock 44.8 s 0.4 s
Issue reproduction, 90 extras, uv lock didn't finish in 120 s 2.3 s
mteb, uv lock with its existing lockfile didn't finish in 5 min 19 s
mteb, uv export --frozen didn't finish in 3 min 7.4 s

mteb has 83 extras, 46 of them in one conflict group. The lockfiles and uv export output are byte-identical to those produced with the existing simplification.

Follow-up

Time and lockfile size still grow with the number of conflicting extras, because UniversalMarker::imbibe rewrites environment-dependent markers as conflicts implies marker, which adds every forbidden pair of extras. Keeping the original marker when the implied form doesn't simplify it would remove those clauses at the source and address #18317, but it changes lockfile output.

@astral-sh-bot

astral-sh-bot Bot commented Oct 10, 2026

Copy link
Copy Markdown

uv test inventory changes

This PR changes the tests when compared with the main base revision.

  • Added tests: 4
  • Removed tests: 0
  • Changed suites: 2
uv-pep508: +2 / -0

Added:

  • uv-pep508::marker::simplify::tests::indexed_matches_linear
  • uv-pep508::marker::simplify::tests::negate_matches_is_negation

Removed: none

uv::lock_scenarios: +2 / -0

Added:

  • uv::lock_scenarios::lock_conflict::conflicting_extras_with_environment_dependent_dependency
  • uv::lock_scenarios::lock_conflict::many_conflicts_with_environment_dependent_dependency

Removed: none

@Samoed

Samoed commented Oct 20, 2026

Copy link
Copy Markdown
Author

Seems this was fixed in uv 0.13.3

@Samoed Samoed closed this Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant