Optimize VMobject
methods which append to points
#3765
Merged
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.
Related PR: #3292
VMobject.append_points()
to build a new NumPy array from scratch withnp.empty()
and copy the old and new points in it, rather than using the slowernp.append()
. This method is slightly faster, which is useful because this method can get called a lot.VMobject.add_points_as_corners()
, which repeatedly calledVMobject.add_line_to()
and thus repeatedly calledVMobject.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..add_line_to()
,.add_points_as_corners()
and.set_points_as_corners()
, instead of always callingnp.linspace(0, 1, self.n_points_per_cubic_curve)
, which is slow when being called many times, I memoized the result into aVMobject._bezier_t_values
NumPy array and simply used that one..start_new_path()
and.add_subpath()
.Reviewer Checklist