Optimized manim.utils.bezier.get_smooth_cubic_bezier_handle_points()
#3767
+483
−146
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.
Overview: What does this pull request change?
Related PR: #3281
get_smooth_cubic_bezier_handle_points()
get_smooth_cubic_bezier_handle_points_for_open_curve()
andget_smooth_cubic_bezier_handle_points_for_closed_curve()
get_smooth_handle_points()
functiondiag_to_matrix()
and thescipy
importMotivation and Explanation: Why and how do your changes improve the library?
I had a test scene with more than 100 ParametricFunctions in it, which were all being updated. More than half of the render time was spent on
ParametricFunction.generate_points()
, and one of the 3 main culprits wasVMobject.make_smooth()
, which made slow calls toget_smooth_handle_points()
.The main bottleneck for this function is the call to
scipy.linalg.solve_banded()
. Apparently, it spends more time validating the arrays passed as a parameter, than actually solving the system of equations.That's why I decided to manually implement the algorithm for solving these equations. But also, all the matrices follow the same pattern and their coefficients are pretty much always the same, varying only in size, so the diagonals can be hardcoded in the algorithm rather than stored explicitly. Some of them can even be memoized, which is what I did.
Links to added or changed documentation pages
Further Information and Comments
Reviewer Checklist