3b1b-manim/manimlib/mobject
Mike Magruder af65c9d5d4
Performance improvement for most scenes (#974)
tl;dr: this is a significant performance improvement for many scenes. 1.7x - 2.6x improvement in animation it/s.

This is a small change to some of the hotest paths in rendering objects. The biggest win comes from not using np.allclose() to check if two points are close enough. In general, NumPy is awesome at operating on large arrays, but overkill for very tiny questions like this. Created a small function to determine if two points are close using the same algorithm, and limited it to 2D points since that's all we need in set_cairo_context_path().

A couple of other minor tweaks to reduce or eliminate other uses of NumPy in this path.

In general, it is better to avoid wrapping lists in np.array when a real NumPy array isn't actually needed.

Added a new file for performance test scenes, with a single scene from the end of a video I've been working on.

Data:

MacBook Pro (16-inch, 2019)
macOS Catalina 10.15.4
2.4 GHz 8-Core Intel Core i9
64 GB 2667 MHz DDR4
Python 3.7.3 (default, Mar  6 2020, 22:34:30)

Profiler: yappi under Pycharm.

Using the scene Perf1 from the included perf_scenes.py, averaged over 5 runs and rendered with:
manim.py perf_scenes.py Perf1 -pl --leave_progress_bars

Before:
Animation 0: FadeInTextMobject, etc.:               8.93it/s
Animation 1: ShowCreationParametricFunction, etc.: 84.66it/s

Profiler shows 48.5% of the run spent under Camera.set_cairo_context_path()

After
Animation 0: FadeInTextMobject, etc.:               23.45it/s  -- 2.63x improvement
Animation 1: ShowCreationParametricFunction, etc.: 149.62it/s  -- 1.77x improvement

Profiler shows 19.9% of the run spent under Camera.set_cairo_context_path()

Less improvement with production-quality renders, and percent improvement varies with scene of course. This appears to be a good win for every scene I'm working on though. I hope it will be for others, too.

NB: there are more perf improvements to be had, of course, but this is the best one I currently have.
2020-04-24 21:04:08 -07:00
..
svg Fix Text wrong display (#889) 2020-04-23 20:36:57 -07:00
types Performance improvement for most scenes (#974) 2020-04-24 21:04:08 -07:00
changing.py Bug fix 2019-07-03 11:07:55 -07:00
coordinate_systems.py Typo in super() 77acc99 2020-02-09 11:31:54 +01:00
frame.py Small changes to frames.py 2019-02-06 22:43:45 -08:00
functions.py Formatting correction 2019-05-27 19:48:14 -07:00
geometry.py Tiny clean to spacing 2019-09-26 11:04:35 -07:00
matrix.py Add options for bracket spacing in Matrix 2019-03-24 11:33:23 -07:00
mobject.py Remove Mobject.print_family, as that is now in utils.debug 2019-12-06 17:10:26 -08:00
mobject_update_utils.py Better behavior for turn_animation_into_updater and cycle_animations 2019-04-02 17:43:18 -07:00
number_line.py NumberLine.default_numbers_to_display was not showing topmost number it should have 2019-06-25 09:03:33 -07:00
numbers.py Moved increment_value method to DecimalNumber 2019-04-06 14:01:04 -07:00
probability.py move library code into manimlib, replace relative imports with absolute imports 2018-12-26 20:57:01 -08:00
shape_matchers.py Forgot to propagate kwargs in Underline 2019-12-12 14:40:08 -08:00
three_d_shading_utils.py move library code into manimlib, replace relative imports with absolute imports 2018-12-26 20:57:01 -08:00
three_d_utils.py move library code into manimlib, replace relative imports with absolute imports 2018-12-26 20:57:01 -08:00
three_dimensions.py Parametric surface should remember what function created it 2019-06-20 13:26:22 -07:00
value_tracker.py Removed unnecessary import 2019-02-10 10:56:08 -08:00
vector_field.py Small formatting changes 2019-03-19 17:30:37 -07:00