-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix quadratic-time ModuleNode.sort_types_by_inheritance #5139
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
Fix quadratic-time ModuleNode.sort_types_by_inheritance #5139
Conversation
This needs further work; will update when it's ready. |
The failing tests are probably mostly an unrelated issue to do with a new version of line_profiler. So they may not be to do with this PR. I'll rerun the tests on this PR when that's fixed. |
thanks! I'm seeing failures on the internal version of this as well, though; I'll have to debug those and add more tests to Cython. |
The problem is the sort comparator I defined isn't a total ordering. I'll have to implement a proper topological sort. |
It should take O(n log n) time now.
b825a21
to
d6b2900
Compare
Co-authored-by: scoder <[email protected]>
Closing and reopening to rerun CI |
I simplified the implementation. @swolchok, could you please validate that this doesn't lead to a performance regression on your side again? |
I'll merge this since it's a major improvement. We can have further PRs if we need more. Thanks! |
At Meta, we have some large .pyx files generated by https://github.com/facebook/fbthrift . I found through profiling that
ModuleNode.sort_types_by_inheritance
was taking about 10% of the time for Cython to process our largest file, and through inspection that it took quadratic time. This PR changessort_types_by_inheritance
to usesorted
to avoid quadratic time, with the result thatsort_type_by_inheritance
take a small fraction of a percent on the same large workload after this change.This function seems to be covered by the
cdef_class_order
andooo_base_classes
tests; they failed during development and now pass.