Skip to content

solver: swap catas with recursion, fuse travs #7519

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

Merged
merged 10 commits into from
Aug 12, 2021
Merged

Conversation

gbaz
Copy link
Collaborator

@gbaz gbaz commented Aug 6, 2021

This is the last refactor I had in mind to address the general performance issues discussed in #7466

It attains some modest but real improvement (mainly in allocations) from eliminating the intermediate cata calls in favor of explicit recursion in the solver tree.

For trav calls, rather than eliminate them entirely, it lifts out their intermediate functions to the top level and explicitly fuses them in the solver pipeline, which yields somewhat more significant improvements.

Overall not the huge win I hoped, but nonetheless given the straightforward nature of the changes to the code, still worth it I think.


go (PChoiceF qpn rdm gr ts) = PChoice qpn rdm gr <$> sequence (W.mapWithKey (goP qpn) ts)
go (FChoiceF qfn rdm gr b m d ts) =
go (PChoice qpn rdm gr ts) = PChoice qpn rdm gr <$> sequence (W.mapWithKey (goP qpn) (fmap go ts))
Copy link
Collaborator

Choose a reason for hiding this comment

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

sequence . map seems bad idea. Should we add traverseWithKey to WeightedPSQ (separately)? Maybe it fuses, but I'm somewhat sceptical about that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure. I take it you don't consider that a blocker for this PR, as its about changing a different thing than this PR currently does. Are you ok with approving this pr as is?

Copy link
Member

Choose a reason for hiding this comment

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

I can fix it up with traverseWithKey in the follow up #7533

Copy link
Member

Choose a reason for hiding this comment

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

Added it first, then pushed to this branch.

@gbaz gbaz added the merge me Tell Mergify Bot to merge label Aug 12, 2021
@gbaz gbaz merged commit 67c440a into master Aug 12, 2021
@emilypi
Copy link
Member

emilypi commented Aug 12, 2021

@Mergifyio backport 3.6

mergify bot pushed a commit that referenced this pull request Aug 12, 2021
* solver: swap catas with recursion, fuse travs

* whoops

* add traverseWithKey to cabal-install-solver (#7533)

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

* replace sequence . mapWithKey with traverseWithKey

* more sequence -> traverse

* Update Preference.hs

fix bad merge

* Update Solver.hs

Co-authored-by: Gershom Bazerman <[email protected]>
Co-authored-by: Emily Pillmore <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 67c440a)

# Conflicts:
#	cabal-install/cabal-install-solver/src/Distribution/Solver/Modular/Preference.hs
#	cabal-install/cabal-install-solver/src/Distribution/Solver/Modular/Solver.hs
@mergify
Copy link
Contributor

mergify bot commented Aug 12, 2021

Command backport 3.6: success

Backports have been created

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