Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track outdated priorities in a set #313

Merged
merged 3 commits into from
Jan 29, 2025
Merged

Conversation

konstin
Copy link
Member

@konstin konstin commented Jan 27, 2025

pubgrub currently assumes that package priorities can only change when the derivations of a package change. In tracks the decision level range where derivations changed, and only updates decisions in this level.

This assumption is incorrect for uv, where the priority doesn't depend on the range, but on specifiers and discovery order per package name, not per DP::P, which contains virtual packages, too. This change enables more flexible priority updating for uv now and for pubgrub generally in the future.

Instead of updating all package priorities in a decision level range, we directly track the set of packages that need to be updated because we changed their derivations. This enables adding pushing priority updates from uv in our fork.

Currently, packages that are removed from prioritization, those that need to be changed and those that are added are all treated the same way, there might be some optimization by telling them apart.

This branch is based on dev...Eh2406:pubgrub:stop-prioritize.

Half of #239, incidentally

pubgrub currently assumes that package priorities can only change when the derivations of a package change. In tracks the decision level range where derivations changed, and only updates decisions in this level.

This assumption is incorrect for uv, where the priority doesn't depend on the range, but on specifiers and discovery order per package name, not per `DP::P`, which contains virtual packages, too. This change enables more flexible priority updating for uv now and for pubgrub generally in the future.

Instead of updating all package priorities in a decision level range, we directly track the set of packages that need to be updated because we changed their derivations. This enables adding pushing priority updates from uv in our fork.

Currently, packages that are removed from prioritization, those that need to be changed and those that are added are all treated the same way, there might be some optimization by telling them apart.

This branch is based on dev...Eh2406:pubgrub:stop-prioritize.
@konstin konstin requested a review from Eh2406 January 27, 2025 12:58
@konstin
Copy link
Member Author

konstin commented Jan 27, 2025

@Eh2406 can you run the cargo perf numbers on this? on uv it's perf neutral with astral-sh/uv#10935

Copy link

codspeed-hq bot commented Jan 27, 2025

CodSpeed Instrumentation Performance Report

Merging #313 will improve performances by 6.38%

Comparing konsti/dev/track-priorities-in-a-set (fa044b1) with dev (e812a8a)

Summary

⚡ 2 improvements
✅ 4 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
large_case_u16_NumberVersion.ron 26.3 ms 25 ms +5.25%
sudoku-hard 4.2 ms 4 ms +6.38%

When the user's implementation breaks the contract about choose version, we now panic. This contract is trivial to enforce (`vs.contains(v)`), so an error path does not make sense.

Fixes #239
// Throw away all stored priority levels, And mark that they all need to be recomputed.
self.prioritized_potential_packages.clear();
self.prioritize_decision_level = self.current_decision_level.0.saturating_sub(1) as usize;
// Throw away all stored priority levels and mark them for recomputing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code this comment refers to has been removed.

@Eh2406
Copy link
Member

Eh2406 commented Jan 28, 2025

I just checked, no measurable difference on CPU time or memory usage for crates.io.

So the question is is the code going to be easier to maintain this way?

@@ -62,8 +63,6 @@ pub(crate) struct PartialSolution<DP: DependencyProvider> {
/// range.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comet ending on this line is now out of date.

@konstin
Copy link
Member Author

konstin commented Jan 29, 2025

So the question is is the code going to be easier to maintain this way?

I find the set-based approach significantly easier to understand.

@Eh2406 Eh2406 added this pull request to the merge queue Jan 29, 2025
Merged via the queue into dev with commit d44ac9d Jan 29, 2025
7 checks passed
@Eh2406 Eh2406 deleted the konsti/dev/track-priorities-in-a-set branch January 29, 2025 16:08
@mpizenberg
Copy link
Member

I find the set-based approach significantly easier to understand.

Sounds logical to me too.

@konstin
Copy link
Member Author

konstin commented Jan 29, 2025

It also looks faster in uv in a quick test (p = 1.18e-08):

$ hyperfine --warmup 2 --export-json a.json "./uv-main pip compile --no-progress scripts/requirements/airflow.in --universal" "./uv-branch pip compile --no-progress scripts/requirements/airflow.in --universal" --runs 100
Benchmark 1: ./uv-main pip compile --no-progress scripts/requirements/airflow.in --universal
  Time (mean ± σ):     111.5 ms ±   5.1 ms    [User: 128.9 ms, System: 108.6 ms]
  Range (min … max):   103.6 ms … 127.4 ms    100 runs
 
Benchmark 2: ./uv-branch pip compile --no-progress scripts/requirements/airflow.in --universal
  Time (mean ± σ):     106.7 ms ±   6.3 ms    [User: 120.3 ms, System: 110.0 ms]
  Range (min … max):    97.8 ms … 134.8 ms    100 runs
 
Summary
  ./uv-branch pip compile --no-progress scripts/requirements/airflow.in --universal ran
    1.05 ± 0.08 times faster than ./uv-main pip compile --no-progress scripts/requirements/airflow.in --universal
(.venv) home ~/projects/uv ⊤  uv run ../hyperfine/scripts/welch_ttest.py a.json 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants