Manim is a Python animation library for creating explainer videos about mathematics – it is perhaps best known for being the video engine behind the popular 3Blue1Brown channel. Manim’s capabilities are less thoroughly tested when it comes to videos about computer science topics such as algorithms and data structures. I was brought on as a developer to experiment with this exact topic, with the goal of producing well-made CS explainers.
An important part of this project was to create high-production-value videos, meaning careful attention to detail when it comes to visual language and aesthetics, tempo and voiceover, and animations with a good “feel”.
Custom animation tools
- Created a custom
CallFunctionanimation which allowed us to call arbitrary functions during playback. We used this to fire events, keep data structures in sync with their visual representations, etc. - Created a
Combineanimation which allows you to provide a “stack” of animations that should be composed. This lets you animate individual attributes and vector components of an object, similar to the capabilities of most game engines and video editors. We were even able to use this class to add simple smear frames by morphing to and from a different vector shape:

Optimization tricks for heavy-duty animations
Manim does fairly little to optimize its rendering, making it very slow to render scenes containing even a few tens of thousands of objects. To be able to efficiently produce our videos, I needed to implement some basic optimiation techniques myself.
- Built a culling system which divides the scene into grid cells and hides any object whose grid cell does not intersect the camera’s frame. For our purposes, this improved rendering times from several hours to roughly 10 minutes. Here’s a zoomed-out example:

- Manim’s animation system often needs to recursively fetch the family tree of all objects in the scene graph, sometimes multiple times every frame. Since our projects often featured objects whose family structure would never change, I added a simple function to memoize the descendant list of important objects, which dramatically improved render times.
- Manim has historically featured many suboptimal implementation choices which are unnoticeable for a casual user, but become prohibitively slow once a scene requires the manipulation of hundreds or thousands of objects. I contributed fixes to the Manim codebase for some of these, such as:
- making index-access in an object’s list of children constant-time rather than linear (link to PR)
- using sets instead of lists to perform linear-time order-preserving list differences, one of Manim’s most used functions (link to PR)
- drastically improving the speed of adding children to and removing children from an object (link to PR)
Custom tweening functions
Like most animation engines, Manim’s animations accept tweening functions to adjust the easing of their speed. Manim has a built-in list which serves most purposes, but we needed finer control, so I built some tweening utilities:
compose, which lets you specify multiple functions to be applied in sequence—very useful for, say, easing in and out at two different ratescompress, which lets you compress another tweening function into a subrange of 0–1. This works well for adding a delay or early finish via an animation’s tweening function.cubic_bezier, essentially a Python version of the CSS function of the same name, letting you produce a bezier curve tweening function just by providing four floats.