-
Notifications
You must be signed in to change notification settings - Fork 75
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
Performance enhancements #372
Conversation
Note that the behavior of |
7cbf632
to
11906d0
Compare
Some more benchmark stats with 11906d0 (replay perf on 1000-step chains, PA congressional):
The |
Updated stats (wrote some better benchmarks):
|
02e5d3c
to
d884a4d
Compare
Note: I will break this up into multiple PRs, so it'll be easier to review. |
I realized that I was profiling #363 incorrectly -- the performance is now as follows:
My bad -- looks like |
e063a39
to
05233ce
Compare
Codecov Report
@@ Coverage Diff @@
## main #372 +/- ##
==========================================
- Coverage 87.89% 87.83% -0.06%
==========================================
Files 37 37
Lines 1660 1669 +9
==========================================
+ Hits 1459 1466 +7
- Misses 201 203 +2
Continue to review full report at Codecov.
|
1cc2d7c
to
848ea4e
Compare
ab7acfa
to
a8e1402
Compare
350f285
to
c55f382
Compare
Memory leak!: GerryChain/gerrychain/partition/partition.py Line 121 in c55f382
|
ce6e5a6
to
fde511f
Compare
… reduce __getitem__ overhead
fde511f
to
5aa7733
Compare
… to prevent double-calculating flows
5aa7733
to
564da2a
Compare
564da2a
to
f06806b
Compare
1d4a69e
to
e387ce4
Compare
Reminder to self: |
cc7be93
to
db18c15
Compare
Note that the "seed_and_freeze" test changed due to the way flows are being cached. Hopefully there are no correctness issues introduced here.
db18c15
to
a31725e
Compare
Closing due to the successful merges of all the broken out PRs. The retworkx PR is still a work-in-progress, but will be ready soon. |
This is a work-in-progress, draft PR with some performance enhancements. In particular,
__slots__
is enabled for a few frequently-created classes (Assignment
andSubgraphView
), resulting in minor performance improvementsnetworkx
's neighbors function is quite expensive and a partition's graph will always remain static)Graph.nodes
andGraph.edges
is cachedCombined, these speedups improve both standard GerryChain run performance and replay performance. In particular, the time it takes to run 100 steps on PA goes from 29.8 seconds to 26 seconds (~13% decrease) and the time spent on each loop when replaying goes from 610 ms (based on #363) to 469 ms (~23% decrease).
Some caveats:
functools.cache
, which is a Python 3.9 feature. We should switch tofunctools.lru_cache
or something with better compatibility with older versions of Python before we merge this in.networkx
graph (to convert anetworkx
graph to agerrychain.Graph
object, a new methodGraph.from_networkx
is introduced in this PR). I had to rewrite the tests accordingly.