Instancing vs BatchedMesh Benchmark (r183 roadmap)

Split-screen benchmark comparing `InstancedMesh` and `BatchedMesh` with synchronized animation, live update timings, and draw-call counters at high instance counts.

Key topics: three.js instancedmesh, batchedmesh, performance benchmark, draw calls, r183

Overview

Both InstancedMesh and BatchedMesh reduce thousands of objects to a single draw call, but they make different trade-offs. This benchmark renders the same animated scene twice, InstancedMesh on the left and BatchedMesh on the right, with live readouts of frame rate, CPU update time and draw calls, so you can compare them at high instance counts on your own hardware.

How it works

The canvas is split with the renderer's scissor and viewport: each frame draws the left scene into the left half and the right scene into the right half. Both sides animate identical motion, so any difference in cost comes from the technique.

  • InstancedMesh stores one matrix per instance in an InstancedBufferAttribute. Updating motion means writing every matrix with setMatrixAt and flagging instanceMatrix.needsUpdate, which re-uploads the whole buffer. Every instance must use the same geometry.
  • BatchedMesh stores matrices in a data texture and supports a different geometry per instance via multi-draw. setMatrixAt marks the texture dirty automatically. It adds a little bookkeeping per instance but gives far more flexibility.

Each overlay reports frames per second, the milliseconds spent updating matrices on the CPU, and the draw calls reported by renderer.info.

Exploring the demo

Raise the instance count towards its maximum and watch the update timings on each side. Both stay at one or two draw calls regardless of count, which is the whole point of these APIs. The update cost grows with the number of instances you modify per frame, so animating everything is the worst case; if most instances were static, both would be much cheaper.

How to choose

If all copies share one geometry, InstancedMesh is the simplest and usually fastest option. If you have many different meshes with a shared material, BatchedMesh avoids splitting them into one instanced mesh per geometry. If the animation can be expressed in a shader, moving it to the GPU removes the CPU update entirely, as shown in instancing performance. See also BatchedMesh opacity and wireframe and frustum culling.

What this code does

- Benchmark Layout: left viewport renders `InstancedMesh`; right viewport renders `BatchedMesh` using equivalent scene conditions.
- High-Count Stress: GUI lets you scale instance count up to thousands to expose update and submission differences.
- Live Telemetry: per-side overlay reports FPS, CPU update cost, and renderer draw-call count in real time.
- Split Rendering: scissor/viewport rendering keeps both techniques visible in one frame for immediate comparison.
- Practical Decision-Making: helps choose batching strategy based on animation update cost and scene composition needs.

Continue Learning

JavaScript Implementation

ES6+
const instanced = new THREE.InstancedMesh(geometry, material, count)

const batched = new THREE.BatchedMesh(
  count,
  maxVertexCount,
  maxIndexCount,
  material
)

// Add one geometry and many instances.
const geometryId = batched.addGeometry(geometry)
for (let i = 0; i < count; i++) {
  const instanceId = batched.addInstance(geometryId)
  batched.setMatrixAt(instanceId, matrix)
}

Related demos

Trending this week

Most popular