TExcelTAD
Home › 3D Web Games with Three.js › Draw Calls & renderer.info

Draw Calls & renderer.info

A browser 3D game has two budgets per frame: what the GPU must shade (pixels, triangles, shadow maps) and what the CPU must prepare (JavaScript game logic, matrix updates, and one draw call per mesh). On desktop GPUs, scenes are often limited by the CPU side long before the triangle count matters: each draw call means JavaScript work in Three.js plus WebGL validation in the browser. A few hundred draw calls are fine everywhere; several thousand will drop the frame rate, especially on phones.

What counts as a draw call

Roughly one per visible mesh per material per render pass:

  • each Mesh (or each material group of a multi-material mesh) that passes frustum culling;
  • again for every shadow map it is rendered into (a shadow-casting point light renders casters six times);
  • again for every extra pass: a CubeCamera, a second viewport, post-processing passes.

Sprites, lines, points and each InstancedMesh count too (one call for all instances).

Measuring with renderer.info

renderer.info counts what the last frame did:

Field Meaning
info.render.calls draw calls in the last render()
info.render.triangles, points, lines primitives drawn
info.render.frame frame counter
info.memory.geometries, info.memory.textures GPU resources currently alive (watch for leaks)
info.programs compiled shader programs (each distinct material setup needs one)

The counters reset at the start of each render() call (info.autoReset = true). If you render several times per frame (shadow maps are part of render(), but viewports and post-processing passes are separate calls), set renderer.info.autoReset = false and call renderer.info.reset() yourself once per frame.

Many meshes vs one merged mesh

The playground renders 2,500 small cubes in three ways. Switch between them and watch the numbers. The frame time is measured on the CPU around renderer.render, smoothed:

  • separate: 2,500 meshes, each with its own material;
  • shared material: 2,500 meshes sharing one material (fewer state changes, still 2,500 calls);
  • merged: all cubes baked into one BufferGeometry with mergeGeometries: one call.
html · try it yourself
<style>html, body { margin: 0; height: 100%; overflow: hidden } canvas { display: block }
#ui { position: fixed; left: 8px; top: 8px; display: flex; gap: 4px }
#ui button { font: 12px system-ui, sans-serif } #ui button.on { outline: 2px solid #4fc3f7 }
#stats { position: fixed; left: 8px; bottom: 8px; color: #fff; font: 12px ui-monospace, monospace; background: rgba(0,0,0,.55); padding: 4px 6px; border-radius: 4px; white-space: pre }</style>
<div id="ui"><button data-m="separate">separate</button><button data-m="shared">shared material</button><button data-m="merged">merged</button></div>
<div id="stats"></div>
<script type="module">
import * as THREE from 'three';
import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js';

const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
document.body.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color('#141925');
const camera = new THREE.PerspectiveCamera(50, innerWidth / innerHeight, 0.1, 200);
camera.position.set(0, 30, 45);
camera.lookAt(0, 0, 0);
addEventListener('resize', () => {
  camera.aspect = innerWidth / innerHeight;
  camera.updateProjectionMatrix();
  renderer.setSize(innerWidth, innerHeight);
});
scene.add(new THREE.HemisphereLight('#fff', '#334', 1.3));
const sun = new THREE.DirectionalLight('#fff', 2);
sun.position.set(5, 10, 7);
scene.add(sun);

const N = 50, GAP = 1.2;                       // 50 x 50 = 2500 cubes
const cubeGeo = new THREE.BoxGeometry(0.8, 0.8, 0.8);
const positions = [];
for (let i = 0; i < N; i++) for (let j = 0; j < N; j++) {
  const x = (i - N / 2) * GAP, z = (j - N / 2) * GAP;
  positions.push([x, Math.sin(i * 0.3) * Math.cos(j * 0.3) * 2, z]);
}
const color = (k) => new THREE.Color().setHSL((k % 50) / 50, 0.6, 0.55);

// 1. separate meshes, one material each
const separate = new THREE.Group();
positions.forEach(([x, y, z], k) => {
  const m = new THREE.Mesh(cubeGeo, new THREE.MeshStandardMaterial({ color: color(k) }));
  m.position.set(x, y, z);
  separate.add(m);
});
// 2. separate meshes, one shared material (vertex colors carry the per-cube color)
const coloredGeo = cubeGeo.clone();
const shared = new THREE.Group();
const sharedMat = new THREE.MeshStandardMaterial({ vertexColors: true });
positions.forEach(([x, y, z], k) => {
  const g = coloredGeo.clone();                // a per-cube geometry only to hold its color
  const c = color(k), cols = new Float32Array(g.attributes.position.count * 3);
  for (let v = 0; v < cols.length; v += 3) cols.set([c.r, c.g, c.b], v);
  g.setAttribute('color', new THREE.BufferAttribute(cols, 3));
  const m = new THREE.Mesh(g, sharedMat);
  m.position.set(x, y, z);
  shared.add(m);
});
// 3. one merged geometry: bake each cube's transform into its vertices
const merged = new THREE.Mesh(
  mergeGeometries(shared.children.map((m) => { m.updateMatrix(); return m.geometry.clone().applyMatrix4(m.matrix); })),
  sharedMat,
);
const modes = { separate, shared, merged };
for (const o of Object.values(modes)) { o.visible = false; scene.add(o); }

let mode = 'separate', ms = 0;
const ui = document.getElementById('ui');
ui.onclick = (e) => {
  const b = e.target.closest('button');
  if (!b) return;
  modes[mode].visible = false;
  mode = b.dataset.m;
  modes[mode].visible = true;
  ui.querySelectorAll('button').forEach((x) => x.classList.toggle('on', x === b));
  ms = 0;
};
ui.querySelector('button').click();
const stats = document.getElementById('stats');

renderer.setAnimationLoop((t) => {
  scene.rotation.y = t / 8000;
  const t0 = performance.now();
  renderer.render(scene, camera);
  const cpu = performance.now() - t0;
  ms = ms ? ms * 0.95 + cpu * 0.05 : cpu;      // smoothed CPU time of render()
  const { calls, triangles } = renderer.info.render;
  stats.textContent = `mode ${mode}\ndraw calls ${calls}\ntriangles ${triangles}\nprograms ${renderer.info.programs.length}\nrender() CPU ${ms.toFixed(2)} ms`;
});
</script>

The triangle count barely changes (30,000 at most; a few separate cubes at the edge are culled when they leave the view); the number of calls drops from about 2,500 to 1. In our test run, render() took about 19 ms of CPU for the separate meshes and about 1.5 ms for the merged one, on a software-rendered headless browser; real machines are faster, but the ratio is typical. Note programs: the 2,500 separate materials still share one shader program, because they have the same type and settings; what costs time is the per-mesh, per-material work in each call. (The measured time is only the CPU side of submitting the work; the GPU finishes drawing later.)

Merging has a price: the merged mesh is one object. You can't move, hide or pick one cube any more, and frustum culling can only keep or drop the whole thing. So merge what never moves (level geometry, props placed once), and use instancing for many copies of the same mesh that do move (InstancedMesh & BatchedMesh).

Reading the numbers in your game

A rough budget for a smooth 60 FPS web game (orders of magnitude, measure on your target devices):

Comfortable on desktop Comfortable on mid-range phones
Draw calls per frame up to ~1,000 ~100–300
Triangles per frame a few million a few hundred thousand
Shadow-casting lights 1–2 0–1
Pixel ratio up to 2 1–2 (capped)

And a frame budget: at 60 FPS everything (game logic, physics, rendering, the browser's own work) must fit into 16.7 ms, so aim for ~10 ms of your own work.

js · try it yourself
// How a 16.7 ms frame budget is spent (example numbers from a profiler run).
const budget = 1000 / 60;
const frame = { input: 0.2, gameplay: 1.6, physics: 2.4, 'animation/mixers': 0.9, 'matrix updates': 1.1, 'render() submit': 3.8 };
let used = 0;
for (const [part, ms] of Object.entries(frame)) {
  used += ms;
  console.log(`${part.padEnd(17)} ${ms.toFixed(1).padStart(4)} ms ${'#'.repeat(Math.round(ms * 4))}`);
}
console.log(`total             ${used.toFixed(1).padStart(4)} ms of ${budget.toFixed(1)} ms (${((used / budget) * 100).toFixed(0)}%)`);
input              0.2 ms #
gameplay           1.6 ms ######
physics            2.4 ms ##########
animation/mixers   0.9 ms ####
matrix updates     1.1 ms ####
render() submit    3.8 ms ###############
total             10.0 ms of 16.7 ms (60%)

Measure each part with performance.now() around it (or the browser's Performance panel), and optimize the biggest bar first. Guessing is how people spend a week shaving a millisecond off physics when 5 ms were going to 3,000 draw calls.

Cutting draw calls

Technique Use for
Share materials (one material per look, not per mesh) everything; fewer programs and state changes
mergeGeometries static level geometry
InstancedMesh many copies of one mesh: trees, rocks, bullets, crowds
BatchedMesh many different meshes with one material, each still movable
Texture atlases let objects with different textures share one material (and be merged/batched)
Frustum culling, LOD, visible = false far away draw less (LOD & Frustum Culling)
Fewer shadow casters small props and particles shouldn't cast shadows

Test yourself

A mesh casts shadows from one directional light. How many draw calls does it typically cost per frame?

  1. 1
  2. 2: one for the shadow map and one for the main pass
  3. 6
  4. 0 if it is merged

2,500 cubes are merged into one geometry. What do you lose?

  1. Lighting
  2. Moving, hiding or picking individual cubes, and per-cube frustum culling
  3. Vertex colors
  4. Shadows

You render a main view and a minimap each frame, and renderer.info.render.calls only shows the minimap's calls. Why?

  1. The main view isn't drawn
  2. The counters reset at each render() call; set info.autoReset = false and reset once per frame
  3. Minimaps use more calls
  4. info only works with one camera