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

Return and track affected and culprit on conflicts #298

Merged
merged 4 commits into from
Dec 18, 2024

Conversation

konstin
Copy link
Member

@konstin konstin commented Dec 16, 2024

Whenever we either discard a version due to its dependencies or perform conflict resolution, we return the last conflict that led to discarding them. In the main solver loop, we count those conflicts and pass their count to the user in prioritize.

In cargo, we use this information for prioritization, which speeds up resolution (cargo run -r -- -m pub --with-solana --filter solana-archiver-lib -t 16 goes from 90s to 20s on my machine).

Configurations that are noticeably slower for the solana test case:

  • All incompatibilities unit propagation
  • Only the last root cause in unit propagation
  • No incompatibilities from unit propagation
  • No incompatibilities from add_version
  • Only affect counts (without culprit counts)
  • Backtracking with the same heuristic as Change backtracking when packages conflict too much astral-sh/uv#9843 (backtracking once after affected hits 5)

In uv, we use this to re-prioritize and backtrack when a package decision accumulated to many conflicts. Since we have our own solver loop, we add the incompatibility to our own tracking instead.

Internally, we track more fields that we expose externally. This allows experimenting with different prioritization schemes without exposing potentially breaking changes in the API.

Built on #291

Benchmarks

Main:

        index commit hash: 82086e46740d7a9303216bfac093e7268a95121f
        index commit time: 2024-11-30T18:18:14Z
               index size: 32
          solana in index: 32
             Pub CPU time:  1215.49s ==  20.26min
           Cargo CPU time: skipped
Cargo check lock CPU time: skipped
  Pub check lock CPU time: skipped
                Wall time:    80.58s ==   1.34min

With #291:

        index commit hash: 82086e46740d7a9303216bfac093e7268a95121f
        index commit time: 2024-11-30T18:18:14Z
               index size: 32
          solana in index: 32
             Pub CPU time:   467.73s ==   7.80min
           Cargo CPU time: skipped
Cargo check lock CPU time: skipped
  Pub check lock CPU time: skipped
                Wall time:    34.76s ==   0.58min

This PR:

        index commit hash: 82086e46740d7a9303216bfac093e7268a95121f
        index commit time: 2024-11-30T18:18:14Z
               index size: 32
          solana in index: 32
             Pub CPU time:   271.79s ==   4.53min
           Cargo CPU time: skipped
Cargo check lock CPU time: skipped
  Pub check lock CPU time: skipped
                Wall time:    20.17s ==   0.34min

Surprisingly, after adding conflicting-ness to the prioritization in any form, the should cancel count and the wall time lose their correlation, i've seen this effect with the other prioritization schemes i tried, too.

Scatterplot

The remaining time seems to be spent mostly in semver(-pubgrub).

Profile

Whenever we either discard a version due to its dependencies or perform conflict resolution, we return the last conflict that led to discarding them.

In cargo, we use this information for prioritization, which speeds up resolution (`cargo run -r -- -m pub --with-solana --filter solana-archiver-lib -t 16` goes from 90s to 20s on my machine).

Configurations that are noticeably slower for the solana test case:
* All incompatibilities unit propagation
* Only the last root cause in unit propagation
* No incompatibilities from unit propagation
* No incompatibilities from `add_version`
* Only affect counts (without culprit counts)
* Backtracking with the same heuristic as astral-sh/uv#9843 (backtracking once after affected hits 5)

In uv, we use this to re-prioritize and backtrack when a package decision accumulated to many conflicts. Since we have our own solver loop, we add the incompatibility to our own tracking instead.

Built on #291

## Benchmarks

Main:

```
        index commit hash: 82086e46740d7a9303216bfac093e7268a95121f
        index commit time: 2024-11-30T18:18:14Z
               index size: 32
          solana in index: 32
             Pub CPU time:  1215.49s ==  20.26min
           Cargo CPU time: skipped
Cargo check lock CPU time: skipped
  Pub check lock CPU time: skipped
                Wall time:    80.58s ==   1.34min
```

With #291:

```
        index commit hash: 82086e46740d7a9303216bfac093e7268a95121f
        index commit time: 2024-11-30T18:18:14Z
               index size: 32
          solana in index: 32
             Pub CPU time:   467.73s ==   7.80min
           Cargo CPU time: skipped
Cargo check lock CPU time: skipped
  Pub check lock CPU time: skipped
                Wall time:    34.76s ==   0.58min
```

This PR:

```
        index commit hash: 82086e46740d7a9303216bfac093e7268a95121f
        index commit time: 2024-11-30T18:18:14Z
               index size: 32
          solana in index: 32
             Pub CPU time:   271.79s ==   4.53min
           Cargo CPU time: skipped
Cargo check lock CPU time: skipped
  Pub check lock CPU time: skipped
                Wall time:    20.17s ==   0.34min
```
@konstin konstin requested a review from Eh2406 December 16, 2024 08:58
Copy link

codspeed-hq bot commented Dec 16, 2024

CodSpeed Performance Report

Merging #298 will degrade performances by 16.8%

Comparing konsti/dev/incompat-tracker (ec324e8) with dev (ffef172)

Summary

⚡ 1 improvements
❌ 1 (👁 1) regressions
✅ 4 untouched benchmarks

Benchmarks breakdown

Benchmark dev konsti/dev/incompat-tracker Change
👁 large_case_u16_NumberVersion.ron 21.5 ms 25.8 ms -16.8%
sudoku-hard 4.2 ms 4 ms +6.17%

konstin added a commit to astral-sh/pubgrub that referenced this pull request Dec 16, 2024
This PR is the child of #36 and
pubgrub-rs#291, providing an
implementation that works for both cargo and uv. Upstream PR:
pubgrub-rs#298.

Specifically, we use the returned incompatibility in
astral-sh/uv#9843, but not
`PackageResolutionStatistics`.

---

Whenever we either discard a version due to its dependencies or perform
conflict resolution, we return the last conflict that led to discarding
them.

In cargo, we use this information for prioritization, which speeds up
resolution (`cargo run -r -- -m pub --with-solana --filter
solana-archiver-lib -t 16` goes from 90s to 20s on my machine).

Configurations that are noticeably slower for the solana test case:
* All incompatibilities unit propagation
* Only the last root cause in unit propagation
* No incompatibilities from unit propagation
* No incompatibilities from `add_version`
* Only affect counts (without culprit counts)
* Backtracking with the same heuristic as
astral-sh/uv#9843 (backtracking once after
affected hits 5)

In uv, we use this to re-prioritize and backtrack when a package
decision accumulated to many conflicts. Since we have our own solver
loop, we add the incompatibility to our own tracking instead.

Built on pubgrub-rs#291

## Benchmarks

Main:

```
        index commit hash: 82086e46740d7a9303216bfac093e7268a95121f
        index commit time: 2024-11-30T18:18:14Z
               index size: 32
          solana in index: 32
             Pub CPU time:  1215.49s ==  20.26min
           Cargo CPU time: skipped
Cargo check lock CPU time: skipped
  Pub check lock CPU time: skipped
                Wall time:    80.58s ==   1.34min
```

With pubgrub-rs#291:

```
        index commit hash: 82086e46740d7a9303216bfac093e7268a95121f
        index commit time: 2024-11-30T18:18:14Z
               index size: 32
          solana in index: 32
             Pub CPU time:   467.73s ==   7.80min
           Cargo CPU time: skipped
Cargo check lock CPU time: skipped
  Pub check lock CPU time: skipped
                Wall time:    34.76s ==   0.58min
```

This PR:

```
        index commit hash: 82086e46740d7a9303216bfac093e7268a95121f
        index commit time: 2024-11-30T18:18:14Z
               index size: 32
          solana in index: 32
             Pub CPU time:   271.79s ==   4.53min
           Cargo CPU time: skipped
Cargo check lock CPU time: skipped
  Pub check lock CPU time: skipped
                Wall time:    20.17s ==   0.34min
```
konstin added a commit to astral-sh/uv that referenced this pull request Dec 16, 2024
Make our implementation compatible with pubgrub-rs/pubgrub#298
konstin added a commit to astral-sh/uv that referenced this pull request Dec 16, 2024
Make our implementation compatible with pubgrub-rs/pubgrub#298
pub(crate) fn unit_propagation(
&mut self,
package: Id<DP::P>,
) -> Result<(), NoSolutionError<DP>> {
) -> Result<Vec<(Id<DP::P>, IncompDpId<DP>)>, NoSolutionError<DP>> {
let mut root_causes = Vec::new();
Copy link
Member

Choose a reason for hiding this comment

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

Nit: like unit_propagation_buffer I bet this Vec ends up expensive to allocate.

Copy link
Member Author

@konstin konstin Dec 16, 2024

Choose a reason for hiding this comment

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

Changed it for a smallvec (it's used a lot less than unit_propagation_buffer)

@Eh2406
Copy link
Member

Eh2406 commented Dec 16, 2024

I do like the overall approach and particularly the code flexibility of this version. Unfortunately, I'm not able to reproduce the performance improvements.

@konstin
Copy link
Member Author

konstin commented Dec 17, 2024

What performance numbers do you get?

@x-hgg-x
Copy link
Contributor

x-hgg-x commented Dec 18, 2024

In my implementation I also get worse performance than #291: Pubgrub CPU time for solana crates goes from 350s to 520s.

unit_propagation_affected: u32,
unit_propagation_culprit: u32,
dependencies_affected: u32,
dependencies_culprit: u32,
Copy link
Contributor

@x-hgg-x x-hgg-x Dec 18, 2024

Choose a reason for hiding this comment

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

dependencies_culprit is never set ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch

@Eh2406
Copy link
Member

Eh2406 commented Dec 18, 2024

Sorry I didn't get you numbers sooner.

Eh2406/pubgrub-crates-benchmark@179f289

> git checkout 179f2895f9d5778e666fbe3fbd585fdc6672334e

> cargo run -r -- -m pub --with-solana --filter solana-archiver-lib -t 16

   Compiling version-ranges v0.1.1 (https://github.com/Eh2406/pubgrub?branch=conflict_count#1044406b)
   Compiling cargo v0.86.0 (https://github.com/rust-lang/cargo?branch=master#876ea2ce)
   Compiling pubgrub v0.2.1 (https://github.com/Eh2406/pubgrub?branch=conflict_count#1044406b)
   Compiling semver-pubgrub v0.1.0 (https://github.com/pubgrub-rs/semver-pubgrub#0cfe3a1c)
   Compiling benchmark_from_crates v0.1.0 (/local/home/jfinkelm/PubGrub/pubgrub-crates-benchmark)
    Finished `release` profile [optimized + debuginfo] target(s) in 1m 09s
     Running `target/release/benchmark_from_crates -m pub --with-solana --filter solana-archiver-lib -t 16`
Running in mode Pub on 16 rayon threads.
!!!!!!!!!! Excluding Yanked !!!!!!!!!!
Start reading index
Done reading index in 26.4s
PubGrub: [Time: 36s, Rate: 0.8969/s, Remaining: 0s] 
!!!!!!!!!! Timings !!!!!!!!!!
        index commit hash: c03a36a091c45203caed5cbed4274a5f404a8c06
        index commit time: 2024-12-16T19:41:05Z
               index size: 32
          solana in index: 32
             Pub CPU time:   357.70s ==   5.96min
           Cargo CPU time: skipped
Cargo check lock CPU time: skipped
  Pub check lock CPU time: skipped
                Wall time:    35.68s ==   0.59min

Eh2406/pubgrub-crates-benchmark@ec4830d

> git checkout ec4830d8211003e5ec24c724fa1e9c7b7189288f

> cargo run -r -- -m pub --with-solana --filter solana-archiver-lib -t 16


   Compiling version-ranges v0.1.1 (https://github.com/Eh2406/pubgrub?branch=conflict_count#65021252)
   Compiling pubgrub v0.2.1 (https://github.com/Eh2406/pubgrub?branch=conflict_count#65021252)
   Compiling semver-pubgrub v0.1.0 (https://github.com/pubgrub-rs/semver-pubgrub#0cfe3a1c)
   Compiling benchmark_from_crates v0.1.0 (/local/home/jfinkelm/PubGrub/pubgrub-crates-benchmark)
    Finished `release` profile [optimized + debuginfo] target(s) in 12.20s
     Running `target/release/benchmark_from_crates -m pub --with-solana --filter solana-archiver-lib -t 16`
Running in mode Pub on 16 rayon threads.
!!!!!!!!!! Excluding Yanked !!!!!!!!!!
Start reading index
Done reading index in 27.1s
PubGrub: [Time: 11s, Rate: 2.8661/s, Remaining: 0s] 
!!!!!!!!!! Timings !!!!!!!!!!
        index commit hash: c03a36a091c45203caed5cbed4274a5f404a8c06
        index commit time: 2024-12-16T19:41:05Z
               index size: 32
          solana in index: 32
             Pub CPU time:   129.76s ==   2.16min
           Cargo CPU time: skipped
Cargo check lock CPU time: skipped
  Pub check lock CPU time: skipped
                Wall time:    11.17s ==   0.19min

Eh2406/pubgrub-crates-benchmark@65fea31

> git checkout 65fea31a3fa63b0f02923240ea23f1c20bc1810d

> cargo run -r -- -m pub --with-solana --filter solana-archiver-lib -t 16

   Compiling version-ranges v0.1.1 (https://github.com/Eh2406/pubgrub?branch=konsti%2Fdev%2Fincompat-tracker#087bcdf5)
   Compiling pubgrub v0.2.1 (https://github.com/Eh2406/pubgrub?branch=konsti%2Fdev%2Fincompat-tracker#087bcdf5)
   Compiling semver-pubgrub v0.1.0 (https://github.com/pubgrub-rs/semver-pubgrub#0cfe3a1c)
   Compiling benchmark_from_crates v0.1.0 (/local/home/jfinkelm/PubGrub/pubgrub-crates-benchmark)
    Finished `release` profile [optimized + debuginfo] target(s) in 12.15s
     Running `target/release/benchmark_from_crates -m pub --with-solana --filter solana-archiver-lib -t 16`
Running in mode Pub on 16 rayon threads.
!!!!!!!!!! Excluding Yanked !!!!!!!!!!
Start reading index
Done reading index in 28.5s
PubGrub: [Time: 31s, Rate: 1.0488/s, Remaining: 0s] 
!!!!!!!!!! Timings !!!!!!!!!!
        index commit hash: c03a36a091c45203caed5cbed4274a5f404a8c06
        index commit time: 2024-12-16T19:41:05Z
               index size: 32
          solana in index: 32
             Pub CPU time:   459.65s ==   7.66min
           Cargo CPU time: skipped
Cargo check lock CPU time: skipped
  Pub check lock CPU time: skipped
                Wall time:    30.51s ==   0.51min

@Eh2406
Copy link
Member

Eh2406 commented Dec 18, 2024

There were two big differences between my test of this branch and my branch. Obviously one of them was how the metrics were collected. The other big change was the removal of discovery_order, I tried running my branch but ignoring discovery_order:

Eh2406/pubgrub-crates-benchmark@787462f

   Compiling benchmark_from_crates v0.1.0 (/local/home/jfinkelm/PubGrub/pubgrub-crates-benchmark)
    Finished `release` profile [optimized + debuginfo] target(s) in 11.56s
     Running `target/release/benchmark_from_crates -m pub --with-solana --filter solana-archiver-lib -t 16`
Running in mode Pub on 16 rayon threads.
!!!!!!!!!! Excluding Yanked !!!!!!!!!!
Start reading index
Done reading index in 26.6s
!!!!!!!!!! Timings !!!!!!!!!!
        index commit hash: c03a36a091c45203caed5cbed4274a5f404a8c06
        index commit time: 2024-12-16T19:41:05Z
               index size: 32
          solana in index: 32
             Pub CPU time:   541.85s ==   9.03min
           Cargo CPU time: skipped
Cargo check lock CPU time: skipped
  Pub check lock CPU time: skipped
                Wall time:    46.21s ==   0.77min

Therefore, I feel comfortable merging this, as long as we follow it up fairly quickly by PR's adding discovery_order. Similarly any other differences in what data is collected can be reevaluated in follow-up PR's.

@konstin konstin added this pull request to the merge queue Dec 18, 2024
Merged via the queue into dev with commit d49bf5f Dec 18, 2024
6 checks passed
@konstin konstin deleted the konsti/dev/incompat-tracker branch December 18, 2024 20:58
@Eh2406
Copy link
Member

Eh2406 commented Dec 18, 2024

In retrospect, the relevant number was "how much does this improve over dev" not "how much does this improve over my PR". Sorry for the distraction. Over dev this is huge! cargo run -r -- -m pub --with-solana --filter solana-archiver-lib -t 16 dev: 24.08min -> this pr: 7.56min.

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