-
Notifications
You must be signed in to change notification settings - Fork 121
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
Refactor get_degrees() to make it faster #732
base: master
Are you sure you want to change the base?
Conversation
Benchmark Results
Benchmark PlotsA plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR. |
Thanks for implementing this, the performance improvement is great. I have a couple concerns:
|
Yes, I think that's because I have added support for
I can do that, but, as I wrote in the description, the dispatching version is 10% faster. |
* replace if op = ... with get_degrees(op, expr) for extendability * avoid sorted_arguments() within get_degrees() * reduce allocations by iterating of degs in efficient way * support /: const/expr and expr/const
keep vectors of degrees to optimize memory usage
For long polynomials get_degree(term) causes most allocations and time. Cashing get_degree(term) to speeds it up and reduces memory footprint.
2c9922a
to
bcec2ee
Compare
I've changed the sorting of negative degree:
That should fix the Symbolics.jl integration tests (I've also added the failing expression to SymbolicUtils.jl unit tests). |
Profiling indicated that in my use case (symbolic multiplication of several large sparse matrices takes almost 1h) a lot of time is spent in
get_degrees()
.So this PR is my attempt to make it faster and use less memory:
get_degrees(op, expr)
) instead ofif op == + .. elseif op == * end
.That increases memory footprint by 10%, but also makes it faster by 10% (I guess type inference is improved).
sorted_arguments()
withinget_degrees()
, as that itself callsget_degrees()
, soget_degrees()
gets called multiple times for the same expression.Instead,
get_degrees()
usesarguments()
and sorts the list of degrees itself.get_degrees(getindex, expr)
: that increases the speed and 2x reduces memory footprint (in the test example below)On the test case I observe 3x speed-up and 3x reduction in memory footprint.
The benchmark script
Results on a master (Julia 1.11.4):
Results for this PR: