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

Optimize VMobject methods which append to points #3765

Merged
merged 3 commits into from
May 23, 2024

Conversation

chopan050
Copy link
Contributor

Related PR: #3292

  • I rewrote VMobject.append_points() to build a new NumPy array from scratch with np.empty() and copy the old and new points in it, rather than using the slower np.append(). This method is slightly faster, which is useful because this method can get called a lot.
  • Also rewrote VMobject.add_points_as_corners(), which repeatedly called VMobject.add_line_to() and thus repeatedly called VMobject.append_points(). Instead of allocating N arrays, one for every time we append a new line to one to the N points, this method now allocates a single array from the beginning and copies all the necessary points in it.
  • At .add_line_to(), .add_points_as_corners() and .set_points_as_corners(), instead of always calling np.linspace(0, 1, self.n_points_per_cubic_curve), which is slow when being called many times, I memoized the result into a VMobject._bezier_t_values NumPy array and simply used that one.
  • Minor optimizations in .start_new_path() and .add_subpath().
  • Added docstrings for some methods.

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

Copy link
Contributor

@JasonGrace2282 JasonGrace2282 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@chopan050 chopan050 merged commit 938b8fc into ManimCommunity:main May 23, 2024
18 checks passed
@chopan050 chopan050 deleted the optimize-point-append branch May 23, 2024 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants