-
Notifications
You must be signed in to change notification settings - Fork 78
Provide direction argument to edge_diffs. #2120
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
Codecov Report
@@ Coverage Diff @@
## main #2120 +/- ##
==========================================
+ Coverage 93.22% 93.29% +0.06%
==========================================
Files 28 28
Lines 26718 26764 +46
Branches 1204 1227 +23
==========================================
+ Hits 24908 24969 +61
+ Misses 1776 1762 -14
+ Partials 34 33 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
I'm fairly sure that we use the edge diffs a lot in tsdate, don't we @awohns ? Perhaps it's worth testing if this causes any perf problems there (I suspect not though, as we are doing some maths on each diff) |
|
That's right @hyanwong, we use the edge diffs a lot. We iterate over them in both the prior and the inside/outside algorithm. Might be good to check if this has a significant effect on tsdate runtime? |
|
That's a good test I think - if this doesn't have a significant impact on a time of a run of tsdate, then I think getting rid of the C linkage is fine, and a small perf regression is something we can live with. If it makes tsdate 2x slower though, then I think we'll have to keep the current C-based implementation for the forwards direction anyway. |
|
@benjeffery - should be push this in for 0.5.0? @awohns - what's the simplest way of testing out the perf implications for tsdate? |
|
If we are doing this (which seems the right thing to do I think) then yes it should be in 0.5.0. |
|
Oh, this would be nice! We were just wanting this! |
|
Results of some perf testing on this: Current: 6 mins 44 seconds. Direction: 7mins 41 seconds. |
|
Right, that's too much of a difference. Will need to think this through again - thanks @awohns! |
|
Hmm, so looks like most of the time for this code is actually spent constructing edge objects and the difference is really about the different code paths we take for that now. Some stats:
So, I think there's room for quite a bit of improvement here and we did have a pretty big perf regression. I wonder if edge metadata is really worth it here, and if we should do something like this: I think if we can get back to the performance of yielding lists of tuples, we can switch the the Python code path and get rid of some C complexity, as this will be a perf improvement over what's currently in the library. @benjeffery, any thoughts? |
9ed70ab to
b3ef71c
Compare
|
I've pushed an additional commit here which removes a function call in the Here are the timings on my machine for 100k trees of 1.6M edges:
I tried a few more tricks, but they added complexity for only a percent or so, not worth it. So we're losing about 25% vs |
|
SGTM. Would the DiffEdge trick I suggested above make any difference or is it basically the same as the current code? |
1f77096 to
9207c06
Compare
|
Using a simple DiffEdge as you described above gets you to 3.55 vs 3.73. It's not nothing, but I don't think that is a big enough win to justify adding a parallel class. |
|
OK then, I guess we should put this to the end-users. @awohns, would you mind trying this version out on your benchmark and letting us know if you're happy with the perf? |
Bumping this one @awohns - as a key user of edge_diffs we'd like to know if the perf drop here is acceptable for your applications. Would you mind checking your benchmark again? (It's also probably relevant for your "bricking" code). We'd like to release 0.5.0 in the next few days. |
|
Sorry, didn't see this until now @jeromekelleher. So here's the timing for creating the tsdate prior of NYGC 1000 genomes chr22 (same file as before; 453,350 trees): And here's the perf for running |
|
Thanks @awohns. I think you should have the casting vote here on whether we keep the existing C code or not then - 10% is a significant perf drop, but not a major one and probably wouldn't be noticed. I honestly don't mind either way as we have the code in both cases (we can keep the current C-based approach as the default), I just want someone else to make the decision! |
|
My 2 cents here is that by Python 3.11 we'll probably get that 10% back. If @awohns doesn't want to make the decision I'm happy to! |
|
Thanks for seeking my feedback @jeromekelleher and for input @benjeffery! |
|
OK, great! @benjeffery - do you want to do the rest here or will I pick it up? |
I can take this from here! |
9207c06 to
64cd79f
Compare
64cd79f to
586ad8d
Compare
|
whoops, took off the AUTOMERGE label there @benjeffery as I'd left some embarassing intermediate commits.Will squash those now. |
586ad8d to
0834427
Compare
|
This also still leaves in the C infrastructure as dead code. Will pull out now. |
|
Documentation isn't finished either. Marking as draft. |
Gah, sorry. I didn't think properly about the C and docs. |
Moves the implementation to Python resulting in a roughly 2X perf regression.
96bfce4 to
ad9adf6
Compare
|
OK, should be ready to go now. |
ad9adf6 to
0d47adb
Compare
Adds a "direction" argument to edge_diffs to allow us to sequentially generate trees in reverse.
Moves the implementation to Python resulting in a roughly 2X perf regression. I doubt this will be significant in practise, because people will usually be doing something with the diffs, which will probably be more expensive. Nonetheless, it is a regression so we should be careful.
If we decide we don't mind about the perf loss for this operation, we can delete some of the Python-C interface boilderplate.
I also modernised the tests for this a bit, while I was in there.
cc @astheeggeggs