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

Speedup OpamVersionCompare by 25% #5518

Merged
merged 3 commits into from
Aug 8, 2024

Conversation

kit-ty-kate
Copy link
Member

@kit-ty-kate kit-ty-kate commented Apr 21, 2023

Doing so does, for example, speeds-up typical opam show <pkg> by 50%

I also tried a completely new implementation of OpamPackage.Version.compare that would have sped-up the comparison function by 30% instead but doing so made OpamPackage.Version.of_string slower, as i was actually parsing the string first and pre-processed it so the comparison function is faster, but it wasn't worth it in the end.

F.i.x.e.s. #5479 as it speeds-up switch loading time from 0.22s to 0.044s on my M1Pro.
Related to #4245 (cc @emillon)

Requires #6078

(* splits a version into (epoch,rest), without the separating ':'. The
* epoch is delimited by the leftmost occurrence of ':' in x, and is ""
* in case there is no ':' in x. *)
let extract_epoch x =
Copy link
Member Author

@kit-ty-kate kit-ty-kate Apr 21, 2023

Choose a reason for hiding this comment

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

Note for reviewers: This was removed because OpamPackage.Version.of_string never allowed :. This is only an unused remnant of the Dose3 implementation.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's good to know - getting rid of the remaining allocs should be a lot easier if we don't need to support epochs!

@rjbou rjbou added this to the 2.2.0~alpha milestone Apr 24, 2023
Copy link
Collaborator

@rjbou rjbou left a comment

Choose a reason for hiding this comment

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

Thanks!!

@kit-ty-kate kit-ty-kate added PR: QUEUED Pending pull request, waiting for other work to be merged or closed and removed STATE: READY TO MERGE labels Apr 25, 2023
@kit-ty-kate kit-ty-kate added STATE: READY TO MERGE and removed PR: QUEUED Pending pull request, waiting for other work to be merged or closed STATE: READY TO MERGE labels Apr 26, 2023
@kit-ty-kate
Copy link
Member Author

Crap, my testing method for opam show and the misspelled command wasn't good.
What I was actually testing was the performance difference between OCaml 4.14.1 and 5.0.0 (how is that giving us 50% performance for free!?!)
Thanks to #5525 we're actually able to detect performance changes reliably so at least that's the good news.

The speedup for OpamVersionCompare is still present but it's not as significant for real-life commands sadly :(

@rjbou rjbou removed this from the 2.2.0~alpha milestone Apr 27, 2023
@rjbou rjbou added PR: WIP Not for merge at this stage PR: NEEDS UPDATE labels May 8, 2023
@kit-ty-kate kit-ty-kate added PR: QUEUED Pending pull request, waiting for other work to be merged or closed and removed PR: WIP Not for merge at this stage PR: NEEDS UPDATE labels Jul 8, 2024
@rjbou rjbou self-requested a review July 9, 2024 09:01
@kit-ty-kate kit-ty-kate added this to the 2.3.0~alpha milestone Jul 9, 2024
@kit-ty-kate kit-ty-kate removed the PR: QUEUED Pending pull request, waiting for other work to be merged or closed label Jul 24, 2024
@kit-ty-kate
Copy link
Member Author

The latest benchmark shows a 18% speedup, in line with the local tests. I believe this is ready to go.

@kit-ty-kate
Copy link
Member Author

After #6144 the PR now improves performance by 28%

Copy link
Collaborator

@rjbou rjbou left a comment

Choose a reason for hiding this comment

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

On the idea and the code itself, lgtm!
I'm wondering if we should update the header as now we are changing that piece of code. Previous version is still the same code that the one in dose (modulo formatting).
Also, can you update the main comment to highlight the change you made, the origin of the speedup.

master_changes.md Outdated Show resolved Hide resolved
src/core/opamVersionCompare.ml Show resolved Hide resolved
src/core/opamVersionCompare.ml Outdated Show resolved Hide resolved
src/core/opamVersionCompare.ml Outdated Show resolved Hide resolved
Copy link
Collaborator

@rjbou rjbou left a comment

Choose a reason for hiding this comment

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

Thanks!!

@rjbou rjbou merged commit 600ac33 into ocaml:master Aug 8, 2024
29 checks passed
@kit-ty-kate kit-ty-kate deleted the speedup-OpamVersionCompare branch August 8, 2024 16:41
@kit-ty-kate kit-ty-kate changed the title Speedup OpamVersionCompare by 15% Speedup OpamVersionCompare by 25% Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants