Skip to main content
This example demonstrates how to structure animations for distributed rendering, where multiple workers render different frame ranges independently and outputs are stitched together.

Overview

The distributed rendering example shows:
  • Stateless frame rendering
  • Deterministic composition structure
  • Frame-independent state calculation
  • Optimizations for parallel execution

Complete implementation

composition.html
main.ts

Key patterns for distributed rendering

Stateless frame calculation

Each frame must be renderable independently without relying on previous frames:

Deterministic calculations

All calculations must be deterministic given only the frame number:

Avoid temporal dependencies

Never store state between frames that affects rendering:

Frame-derived randomness

Use deterministic random functions seeded by frame number:

Distributed rendering architecture

Worker assignment

Divide frame ranges among workers:

Frame seeking

Jump directly to any frame without replaying previous frames:

Output stitching

Combine worker outputs without re-encoding:

Performance tips

Optimize initialization

Minimize per-frame initialization by separating setup from rendering:

Cache expensive calculations

Store results that don’t change between frames:

Use typed arrays

Typed arrays are faster for numeric data:

Minimize garbage collection

Reuse objects instead of creating new ones each frame:

Advanced techniques

Chunk-based rendering

Render in chunks to balance load and enable checkpointing:

Dynamic work distribution

Assign work based on worker speed:

Fault tolerance

Implement retry logic and checkpointing:

Parallel composition

Render multiple compositions simultaneously: