Faster mentions#367
Open
EdouardHeitzmann wants to merge 7 commits into
Open
Conversation
…s are already materialized
Collaborator
Author
|
Ok well it seems like the 3.11 tests are broken -- I'm not sure if this is my doing (and if so, how I did that). Lmk |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I got tired of waiting >5 seconds every time I need to compute mentions for large profiles.
The legacy mentions function in
votekit/utilsuses the Profile's.ballotsproperty to compute ballots; when this property is not already set, it is computed and cached whenmentionsis called. This is quite slow when we are passing a large profile that was loaded via a cvr loader that relies on a pandas df rather than a list of ballots to create the profile. This PR introduces a new pandas-only way to compute mentions in such a case, which is around 14-20x faster on my machine for the Portland profiles.When the ballot list is already materialized, the legacy
mentionsare faster; in such a case thefast_mentionsfunction I'm adding defaults back to said legacy function.I also add a few extra tests for both the old and the new mentions functions to verify intended behavior on profiles with repeated and tied rankings (although the former is probably not the intended use case).
Some things worth considering as part of this PR:
mentionshere, and I named my additionfast_mentions; we might just want to replacementionscompletely instead.Fractionoutputs, if we care (cf. Issue Add back in Fraction support #358). I am happy to do this if desired (this would involve me chasing down other places mentions are used in votekit and tinkering with the typing).