-
Notifications
You must be signed in to change notification settings - Fork 710
Add 'WeightedPSQ' and use it to sort package, flag, and stanza choices. #3594
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
Conversation
@grayjay, thanks for your PR! By analyzing the annotation information on this pull request, we identified @kosmikus, @edsko and @martinvlk to be potential reviewers |
Let me be the grumpy code reviewer:
But I'm all for defining data structures we need. |
@grayjay Looks promising so far. It doesn't seem to have any negative performance impact afaics. |
Thanks. I moved @kosmikus How do you want to proceed? Should I open a new PR with just |
I cleaned it up, added tests, and added documentation with asymptotics, similar to D.Compat.Graph. It's ready for review. I'd like to clean up the history before it is merged, though. |
filter :: (v -> Bool) -> WeightedPSQ k w v -> WeightedPSQ k w v | ||
filter p (WeightedPSQ xs) = WeightedPSQ (L.filter (p . triple_3) xs) | ||
|
||
-- | /O(N)/. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ouch! Should there be a TODO here to track the length separately? (Or maybe there's a good reason not to do it eagerly related to laziness?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
length
is actually no longer called. I think it was used by --reorder-goals, which now uses degree
to avoid traversing the whole list. Calling length
there had a significant impact on performance because it was called on the children of every available goal choice after the children were filtered with an expensive predicate. I'll remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thanks.
be60f86
to
8a7eb35
Compare
I was done working on it, but I wasn't sure if @kosmikus wanted to take another look. |
Let's merge then, if @kosmikus dislikes something he can always revert. |
The space leak was introduced in haskell#3594. haskell#3594 added a new variable, sortedVersions, to sort the subtrees under package choice nodes in the search tree. However, sortedVersions referenced the subtrees and caused them to be retained when it was not used. This commit forces evaluation of sortedVersions.
I split this out from #2917 because the data structure is also needed for goal-scoring (#3488).
WeightedPSQ
associates weights with choices in the search tree. This PR usesWeightedPSQ
for package, flag, and stanza choices andPSQ
for goal choices, but eventually all choices should useWeightedPSQ
. There are a few TODOs in the code./cc @kosmikus
EDIT: This PR uses
[Double]
as the weight type to avoid changing the behavior of the solver.