All writing
3 min read

Why I wrote a Spine runtime for PixiJS

Slot scenes are full of small Spine skeletons, and the official runtime gives each one its own draw call and uploads it every frame. pixi-marrow batches them, lets idle skeletons skip work, and keeps poses identical to the official runtime.

In short

  • In slot scenes most Spine skeletons are small and mostly still. The official runtime still poses and uploads each one every frame.
  • pixi-marrow batches small skeletons into one draw call and rewrites data in place, so Pixi does not rebuild its render instructions.
  • Skeletons at rest skip posing and upload nothing.
  • Poses match the official runtimes exactly, checked on 135 skeleton files.

The problem

A slot screen has fifteen symbols on the reels, each with an idle and a win animation, plus coins, sparkles and often a character. Most of these skeletons are small, and most of the time they do almost nothing.

The official spine-pixi-v8 runtime is correct and complete. It treats each skeleton separately, and in slot scenes the separate costs add up. I wrote down the costs that kept appearing in profiles:

  1. One runtime package supports one Spine version. Studios deliver 4.1, 4.2 and 4.3 exports, sometimes for the same game.
  2. A blend-mode change starts a new batch. One additive glow slot splits a symbol into three draw calls.
  3. Changes to draw order or attachments make Pixi rebuild its render instructions.
  4. A skeleton that holds a still pose is posed and uploaded every frame.
  5. Clipping runs on the CPU and forces rebuilds.

pixi-marrow is a runtime built to remove those costs.

Batching without rebuilds

For rigs up to 1024 vertices, marrow feeds two custom batchers into Pixi's batch pipe. Each skeleton reserves a fixed amount of space: room for its largest attachment, with unused indices filled by degenerate triangles. When the draw order changes, a slot hides or an attachment swaps, marrow rewrites the data in place. The size does not change, so Pixi does not rebuild instructions. Additive slots stay in the same batch.

The 1024-vertex limit comes from a measurement: batching saves about 2.7 µs per instance and costs about 5 ns per vertex, so the two meet near 570 vertices. Larger rigs use mesh mode, which draws up to 8 atlas pages in one call and supports GPU skinning and instancing.

Idle skeletons

marrow keeps a stamp of everything that affects a pose. If nothing changed since the last frame, the skeleton skips posing and uploading. With 200 instances at rest, an update takes 0.02 to 0.04 ms and uploads nothing. The official runtime uploads 0.2 to 3.4 MB per frame for the same scene.

Results

Measured with headless Chrome on an Apple M4, pixi.js 8.23, 200 instances, WebGL2:

RigDraw callsFrame timeMemory per instance
coin-pro1 (official: 400)1.03 ms (3.46)16.5 KB (15.3)
raptor-pro1 (1)4.23 ms (7.01)70 KB (105)
tank-pro401 (about 488)8.17 ms (20.66)156 KB (283)

The coin rig uses slightly more memory per instance, because each element reserves its fixed space.

These are desktop measurements. They do not say how phones behave. GPU skinning stays off by default until I have measured it on phones.

Identical poses

A runtime that is faster but poses a skeleton slightly differently is not usable: animations are approved by clients, and a drift of one pixel is visible.

marrow's pose code is a port of the official runtimes. It does the arithmetic in the same order with 64-bit values. The parity suite runs 2,970 seeded cases on 135 skeleton files and prints the seed of any case that differs. A render check compares marrow's output with spine-pixi-v8 pixel by pixel. The largest difference today is 4/255 in one channel.

The parity work found a bug in the official binary readers: they ignore the byte offset of a typed array, so a skeleton loaded from part of a larger buffer reads the wrong bytes. marrow uses the offset.

A WebGPU limit

Pixi's WebGPU backend gives each mesh draw a slot in a shared uniform buffer, with 2,047 slots per frame. A test scene with 1,200 clipped instances ran out of slots and threw an error. marrow now wraps Pixi's mesh adaptor and moves meshes to their own buffers when fewer than 256 slots remain. This uses private Pixi fields, and the code documents that.

Status

pixi-marrow 0.3 runs on WebGL2, WebGPU and WebGL1, and plays Spine 4.1, 4.2 and 4.3 in one scene. pixi-marrow/diagnose checks a skeleton against 25 performance rules and explains what each finding costs.

Still open before 1.0: a migration guide from the official runtime, and batching across non-marrow objects. Today a Pixi object between two skeletons breaks marrow's batch. Docs and a playground are at pixi-marrow.schmooky.dev.