Skip to content
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

Optimized manim.utils.bezier.get_smooth_cubic_bezier_handle_points() #3767

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

chopan050
Copy link
Contributor

@chopan050 chopan050 commented May 16, 2024

Overview: What does this pull request change?

Related PR: #3281

  • Optimized get_smooth_cubic_bezier_handle_points()
  • Added auxiliar functions get_smooth_cubic_bezier_handle_points_for_open_curve() and get_smooth_cubic_bezier_handle_points_for_closed_curve()
  • Deleted duplicated get_smooth_handle_points() function
  • Removed the auxiliar function diag_to_matrix() and the scipy import

Motivation 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 was VMobject.make_smooth(), which made slow calls to get_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

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

@chopan050 chopan050 changed the title Optimized manim.utils.get_smooth_cubic_bezier_handle_points() Optimized manim.utils.bezier.get_smooth_cubic_bezier_handle_points() May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🆕 New
Development

Successfully merging this pull request may close these issues.

None yet

1 participant