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

Reduce allocations in opamVersionCompare #6144

Merged
merged 1 commit into from
Aug 7, 2024

Conversation

talex5
Copy link
Contributor

@talex5 talex5 commented Aug 7, 2024

Test-case:

let ()
  let x0 = Gc.stat () in
  assert (OpamVersionCompare.compare "1.2.3" "1.02.3" == 0);
  let x1 = Gc.stat () in
  Printf.printf "minor_words: %.0f\n" (x1.minor_words -. x0.minor_words)

Before: minor_words: 156
After: minor_words: 84

This just passes all the parameters to loop rather than getting them from the context. Then loop itself isn't needed.

Ideally, there would be no allocations at all. However, removing the others makes the code quite messy so I just did the easy change here.

See https://roscidus.com/blog/blog/2024/07/22/performance-2/#statmemprof for some real-world profiling of the CI solver service, showing this to be a problem.

Test-case:

    let ()
      let x0 = Gc.stat () in
      assert (OpamVersionCompare.compare "1.2.3" "1.02.3" == 0);
      let x1 = Gc.stat () in
      Printf.printf "minor_words: %.0f\n" (x1.minor_words -. x0.minor_words)

Before: minor_words: 156
After:  minor_words: 84
@kit-ty-kate kit-ty-kate added this to the 2.3.0~alpha milestone Aug 7, 2024
@kit-ty-kate
Copy link
Member

Thanks a lot for this contribution. Would you be able to rebase it on top of #5518 ? I believe with both it should be able to reduce allocation further

Copy link
Member

@kit-ty-kate kit-ty-kate left a comment

Choose a reason for hiding this comment

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

Our automated benchmark shows a 18% performance improvement. lgtm

@kit-ty-kate kit-ty-kate added STATE: READY TO MERGE AREA: PERFORMANCE PR: QUEUED Pending pull request, waiting for other work to be merged or closed and removed STATE: READY TO MERGE labels Aug 7, 2024
@talex5
Copy link
Contributor Author

talex5 commented Aug 7, 2024

I've pushed a commit just to test it on top of #5518. Will need squashing if we decide to keep it.

@kit-ty-kate
Copy link
Member

With both work it improves performance by 41%! 🎉

@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 labels Aug 7, 2024
@kit-ty-kate
Copy link
Member

I've put back the previous state and will merge this as soon as CI finishes, i'll update my PR on top of master after. Thanks again!

@kit-ty-kate kit-ty-kate merged commit 6effccc into ocaml:master Aug 7, 2024
57 checks passed
@talex5 talex5 deleted the compare-fewer-alloc branch August 7, 2024 17:45
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