Repository navigation
08 Caching and Limits
English · 简体中文 · 繁體中文 · 日本語 · 한국어 · हिन्दी · Español · Português · Français · Deutsch · Русский
RTM's performance comes from not redoing the same work every frame. The caches live at several levels:
| Cache | Location | Invalidated by |
|---|---|---|
| text/math compilation | manim media/Tex, media/texts
|
content change / clear_tex_cache()
|
| ImageMobject textures | mob._rtm_tex_cache |
_rtm_tex_rev / _rtm_alpha_rev
|
| batched emission |
_rtm_quad_run / _rtm_poly_run
|
geometry, viewport or colour change |
| mesh projection |
MeshBatch._projected, _idx_key, _lit_key
|
mark_geometry_dirty() / viewport change |
| static layer | MLWindow._static_layer |
camera/background/updater change |
| 3D face shading | mob._rtm_shade_cache |
geometry/colour/light change |
- with the
[typst]extra installed,MathTexuses an in-process Typst backend and needs no LaTeX; - compiled output lands in manim's media cache;
- parallel workers get private media directories so SVGs and temp files cannot collide;
-
restore_tex_cache/save_tex_cachemove a compilation cache between machines.
send_image only does real work for textures that actually changed:
- fully transparent images are skipped before any pixel work based on alpha;
- static images cache the opaque RGBA buffer, digest and ctypes copy;
-
set_opacitywith a uniform alpha only changes quad opacity instead of rewriting pixel alpha; - per-pixel masks are still re-uploaded (camera frames rely on revision counters).
-
append_indexedprojects unique vertices once; - while viewport and geometry are unchanged, projection, gather and the index buffer are reused;
-
mark_geometry_dirty()is the manual invalidation hook.
Roots without updaters can be baked into one texture, after which each frame draws a single image quad. The price is "frozen pixels", so any updater — including one that writes other objects — disables baking.
A frame's cost roughly splits into:
CPU: walk paint units → project → fill native commands/vertices
GPU: upload → mesh → painter → images → post
IO: readback → ffmpeg (while recording)
Some rules of thumb at 1080p:
- an empty
FrameServer.render_frameis millisecond-scale; - text/curve-heavy scenes are dominated by CPU emitters and vertex counts;
- large meshes cost mostly Python projection + vertex upload, not draw calls;
- bloom/tonemap is one full-screen copy plus a half-resolution pass, about 0.4 ms of GPU at 1080p;
-
jobs=Nis not linear: readback, encoding, memory bandwidth and process startup all eat into the gain.
RTM_DIAGNOSTICS=1 prints one line per play:
[rtm] play 3: 60f 0.42s | static=on mesh=0v tex_uploads=0 post=off
Meaning:
-
static=on/off: whether the static layer took part; -
mesh=...v: peak mesh vertex count for this play; watch it near 262k/524k; -
tex_uploads: real texture uploads; -
post=on/off: whether post-processing is enabled.
RTM_AUTO_DEPTH_DEBUG=1 prints root and vertex counts for the automatic depth path.
- 1920×1080@60: resolution and frame rate are fixed; other values are corrected with a notice.
- One window per process: native Vulkan state is process-global; parallel recording uses multiple processes.
- No per-pixel transparency sort for meshes: coplanar translucent geometry blends in submission order.
-
Stateful animations:
Rotate,SpeedModifier, animations with updaters, and custominterpolate_mobjectthat depends on outside state cannot guarantee pure-function semantics for arbitrary seeks. - macOS: needs MoltenVK; newer native features (bloom, lit mesh, painter depth) should be validated at runtime on a Mac.
-
ffmpeg: required on
PATHfor recording.
| Symptom | Likely cause | Fix |
|---|---|---|
| slow with lots of text | recompiling/re-sending glyphs every frame | use caches, avoid rebuilding Text per frame |
| slow surfaces | painter submits faces one by one |
MeshBatch.from_surface / RTM_AUTO_DEPTH
|
| wrong recorded frame count | estimating with duration*fps
|
use Timeline.frame_times
|
| visible seam between parallel chunks | H.264 I-frame quantisation | lossless intermediate, or compare on the same keyframe |
| half the picture missing | vertex count above MAX_VERTICES
|
split the scene / reduce bezier subdivision |
| won't start on mac | MoltenVK missing | brew install molten-vk |
-
real_time_manim/render/image.py: image texture cache -
real_time_manim/window/core.py: static layer, mesh submission -
real_time_manim/window/play.py: static-layer preparation, diagnostics line -
real_time_manim/render/util.py: 3D shading cache -
real_time_manim/util.py: text cache helpers
Measured speedups per scene type: 09 Performance by Scene Type.
English · 简体中文 · 繁體中文 · 日本語 · 한국어 · हिन्दी · Español · Português · Français · Deutsch · Русский
English
- Home
- 01 Overview & Architecture
- 02 Runtime Model
- 03 Timeline & Frame Addressing
- 04 Paint Queue & Ordering
- 05 The Native Vulkan Layer
- 06 Recording & Parallelism
- 07 Meshes & 3D
- 08 Caching, Performance & Limits
- 09 Performance by Scene Type
- 10 The llms.txt Strategy
中文
- 首页
- 01 总览与架构
- 02 运行模型
- 03 时间线与帧寻址
- 04 绘制队列与顺序
- 05 原生 Vulkan 层
- 06 录制与并行
- 07 网格与 3D
- 08 缓存、性能与边界
- 09 场景类型性能基准
- 10 llms.txt 的策略
Other languages: open the Home page of a language from the bar above — its chapter lists live there.