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

perf: fewer intersections in satisfier #174

Merged
merged 17 commits into from
Jan 3, 2024
Merged

perf: fewer intersections in satisfier #174

merged 17 commits into from
Jan 3, 2024

Conversation

Eh2406
Copy link
Member

@Eh2406 Eh2406 commented Dec 21, 2023

This is some "straightforward" re-factoring to the satisfier code to take advantage of #171. This is not my first time following this line of inquiry. In previous attempts I have only saved the final solution, and then not been confident that the final solution had the same semantics as the original. So this time I kept a separate commit for each transformation. I also kept the original code around with debug asserts to make sure they had the same behavior. Each commit passes all tests. I would strongly recommend reviewing this one commit at a time, and looking at the commit message for why I thought it was correct.

Some highlights: 1299c67 goes from 2 intersections to 1 for each decision searched in the history. 5127437 goes from a linear to a logarithmic scan. 78f8fb1 and the commits that follow are just things I noticed while staring at this code and can be left for follow-up PRs if their controversial.

As for performance the normal benchmarks think this is lost in the noise. Because they don't do much backtracking and intersection is fairly cheap. The new synthetic benchmark slow_135_0_u16_NumberVersion improves its runtime by 82%!

@mpizenberg
Copy link
Member

This is quite the list of changes. I've made a first read pass. Most of things seem ok, but I was very skeptic about what I read here 2ee7c08. Implications (=>) is not equivalence (<=>). I'll have to re-read all that at a more reasonable hour.

@Eh2406 Eh2406 force-pushed the fewer_intersections branch from 6e72a2b to 8b6852f Compare December 22, 2023 01:04
@Eh2406
Copy link
Member Author

Eh2406 commented Dec 22, 2023

I made such a long list of changes so that it would be easy to call out exactly where I had made an incorrect leap of logic. That does seems suspicious. I am comforted by the assertion passing, but that doesn't mean I can prove it's valid. ... Speaking of the assertion, I used cfg(test) not cfg(debug_assertions), let's see if it still works with that fixed. Yes it did. Sorry for the force push.

I'm going to set the prop tests to keep running overnight, and see if they found anything by the morning.

@Eh2406
Copy link
Member Author

Eh2406 commented Dec 22, 2023

So here's the way I'm thinking about it at the moment, there are four kinds of versions. A version can either be contained in accumulated_intersection.intersection(start_term) (for space called accumulated) or not, simultaneously the version can either be contained in incompat_term or not.

term type 1 type 2 type 3 type 4
accumulated True True False False
incompat_term True False True False
accumulated.intersection(incompat_term) True False False False
accumulated.intersection(incompat_term) == accumulated (aka old) True False True True
accumulated.intersection(incompat_term.negate()) False True False False
accumulated.intersection(incompat_term.negate()) == empty (aka new) True False True True

(Edit: Now that I have fixed my mistakes) It looks to me like it is correct.

@Eh2406 Eh2406 force-pushed the fewer_intersections branch from 8b6852f to 5ca8972 Compare December 22, 2023 17:12
@Eh2406
Copy link
Member Author

Eh2406 commented Dec 22, 2023

Having run the prop tests overnight, they still haven't found anything.

@mpizenberg
Copy link
Member

Having run the prop tests overnight, they still haven't found anything

That's great!

I'm taking some family time for the end of year so probably won't have a more in-depth review of this until the new year. I'd like to review this more in depth, but don't want to be a big blocker if you have a lot more planned during this period.

@Eh2406
Copy link
Member Author

Eh2406 commented Dec 23, 2023

Please enjoy your holidays with no stress from this project. I suspect you will not be the only one with limited time to look at this. (I'm very excited to see how much difference this makes on the non-synthetic cases, but I must be patient.)

@Eh2406
Copy link
Member Author

Eh2406 commented Dec 25, 2023

I discussed this with a mathematician friend tonight. I believe the transformation is correct, and is easier to understand starting a little further back. (Utilizing the shorthand accumulated for accumulated_intersection.intersection(start_term)) The original formulation was accumulated.subset_of(incompat_term). This asks if there is an element of accumulated that is not in incompat_term. accumulated.intersection(incompat_term.negate()) directly computes all the versions in accumulated that are not in incompat_term.

@Eh2406 Eh2406 force-pushed the fewer_intersections branch from 5ca8972 to 8b6852f Compare December 27, 2023 02:36
konstin pushed a commit to astral-sh/pubgrub that referenced this pull request Dec 28, 2023
konstin pushed a commit to astral-sh/pubgrub that referenced this pull request Dec 28, 2023
@konstin
Copy link
Member

konstin commented Dec 28, 2023

Great work!

main: 1fd7ec3
branch: 201d0b7

tf-models-nightly main

real 0m2,533s
user 0m2,226s
sys 0m0,303s

tf-models-nightly branch

real 0m1,235s
user 0m0,949s
sys 0m0,292s

bio_embeddings main

real 1m42,222s
user 1m40,462s
sys 0m1,651s

bio_embeddings branch

real 0m32,804s
user 0m30,528s
sys 0m1,740s

@Eh2406 Eh2406 force-pushed the fewer_intersections branch 2 times, most recently from 46d783d to e60b6be Compare January 2, 2024 19:51
previous_satisfier_level,
};
(satisfier_package, search_result)
let search_result = if previous_satisfier_level >= satisfier_decision_level {
Copy link
Member

Choose a reason for hiding this comment

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

The >= is a bit weird to read for "same decision level" no? shouldn't it be == ? I might have forgotten but the search starts at the same decision level right? so it could not go > ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I believe == would also be correct. The re-factoring tool gave me >= when flipping the if as a simplification of !(previous_satisfier_level < satisfier_decision_level). How should we leave it?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm going to call it defensive coding, and if we change our mind PR's are cheap.

Copy link
Member

@mpizenberg mpizenberg left a comment

Choose a reason for hiding this comment

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

Ok, sounds good

@mpizenberg
Copy link
Member

I discussed this with a mathematician friend tonight. I believe the transformation is correct, and is easier to understand starting a little further back. (Utilizing the shorthand accumulated for accumulated_intersection.intersection(start_term)) The original formulation was accumulated.subset_of(incompat_term). This asks if there is an element of accumulated that is not in incompat_term. accumulated.intersection(incompat_term.negate()) directly computes all the versions in accumulated that are not in incompat_term.

Thanks for that!

konstin pushed a commit to astral-sh/pubgrub that referenced this pull request Jan 3, 2024
@Eh2406 Eh2406 force-pushed the fewer_intersections branch from e60b6be to a890799 Compare January 3, 2024 18:12
@Eh2406 Eh2406 added this pull request to the merge queue Jan 3, 2024
Merged via the queue into dev with commit 4a48371 Jan 3, 2024
5 checks passed
@Eh2406 Eh2406 deleted the fewer_intersections branch January 3, 2024 18:41
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