Setting a Performance Budget for a 3D or Interactive Website
The numbers to agree before anyone builds a 3D scene: download size, GPU memory, draw calls and triangles, plus the glTF Transform commands, Three.js loader setup and build check that keep a site inside them.
Most slow 3D websites are not slow because of Three.js. They are slow because a designer exported a beautiful 80 MB model, a developer dropped it into the page, and nobody had agreed in advance what “too big” meant.
A performance budget is that agreement. It is a short list of numbers the scene must stay under, written down before modelling starts and checked every time the site is built. It turns “the site feels heavy on my phone” into “the hero model is 2.4 MB over budget”, which is a problem someone can actually fix.
The budget lines that matter for 3D
A normal website budget talks about JavaScript size and image weight. A 3D site needs those plus a few that only exist once a GPU is involved:
| Budget line | What it limits | Why it matters |
|---|---|---|
| Compressed model download | Bytes of .glb and texture files sent over the network |
Mobile data, time before the scene appears |
| GPU texture memory | Memory the textures occupy once uploaded to the graphics card | Tab reloads and crashes on phones |
| Draw calls per frame | How many separate render instructions the scene issues | The main cause of low frame rates on mid-range phones |
| Triangles per frame | Geometry the GPU processes | Frame rate, battery, heat |
| JavaScript for the 3D layer | Three.js, loaders, decoders and your scene code | Main thread time, which affects INP |
The page itself still has to pass Core Web Vitals: Largest Contentful Paint (LCP) of 2.5 seconds or less, Interaction to Next Paint (INP) of 200 milliseconds or less, and Cumulative Layout Shift (CLS) of 0.1 or less, measured at the 75th percentile of real visits. The 3D budget is what protects those numbers.
We do not publish universal targets for each line, because a configurator that is the whole point of the page can afford more than a decorative hero. What we do is fix the numbers per project, test them on the cheapest phone the client’s customers realistically use, and write them into the repository.
Download size and GPU memory are different problems
This is the one most teams miss. A PNG or JPEG texture is small on the network, but the GPU cannot use it in that form. It gets decoded and stored uncompressed in GPU memory.
The maths is simple. A 2048 × 2048 texture with four channels is 2048 × 2048 × 4 bytes, roughly 16 MB, and mipmaps add about a third on top. A model with a base colour, normal and roughness map at that size is using around 64 MB of GPU memory, even if the files downloaded in 3 MB. Do that across a few models and a phone browser will start reloading the tab.
So there are two separate tools:
- WebP or AVIF textures shrink the download. In GPU memory they are still fully uncompressed.
- KTX2 textures (Basis Universal) stay compressed on the GPU, so they cut memory and upload time. They need more care with settings to look as good.
Picking the right one per texture is part of meeting the budget. Decorative backgrounds can go small and WebP. Textures on a product the customer will zoom into usually justify KTX2.
Draw calls are the frame rate budget
Every separate mesh with its own material is usually at least one draw call. A scene built from 400 small objects can stutter on a phone even if its triangle count is modest, because the CPU spends the frame issuing instructions instead of the GPU drawing.
Measure it rather than guess. In Three.js with WebGLRenderer, the info object reports what the last frame did:
// Development only: log scene cost once a second
let last = 0;
function animate(time) {
renderer.render(scene, camera);
if (import.meta.env.DEV && time - last > 1000) {
const { calls, triangles } = renderer.info.render;
const { geometries, textures } = renderer.info.memory;
console.table({ calls, triangles, geometries, textures });
last = time;
}
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
If calls is far above your budget, the fixes are structural: merge meshes that share a material, use instancing for repeated objects such as chairs or trees, and combine small textures into one so more meshes can share a material.
Getting a model inside the budget with glTF Transform
glTF Transform is an open source toolkit for optimising .glb and .gltf files, and its command line tool does most of this work in one pass.
Start by finding out where the weight is:
npm install --global @gltf-transform/cli
gltf-transform inspect hero.glb
The report breaks the file down by meshes, materials, textures and animations, so you can see whether the problem is geometry, textures or simply too many separate meshes.
Then optimise. The optimize command joins meshes, applies instancing, removes unused data, welds and simplifies geometry, resizes textures and compresses. Its defaults use Meshopt for geometry and cap textures at 2048 pixels. For a hero model on a business site, we usually tighten it:
# Smaller download, textures as WebP, max 1024px
gltf-transform optimize hero.glb hero.opt.glb \
--compress meshopt \
--texture-compress webp \
--texture-size 1024
# Lower GPU memory: textures as KTX2 instead
gltf-transform optimize product.glb product.opt.glb \
--compress meshopt \
--texture-compress ktx2 \
--texture-size 2048
Run inspect again on the output and compare. Then look at the model on screen, because simplification and texture compression can soften details. If edges look wrong, turn off simplification with --simplify false rather than giving up on the rest.
Keep the original file in the repository and treat the optimised file as a build output. Designers will send revisions, and you want to rerun the same command, not repeat manual export settings from memory.
Loading compressed files in Three.js
Meshopt geometry and KTX2 textures need their decoders registered on the loader, otherwise the model fails to load:
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { KTX2Loader } from 'three/addons/loaders/KTX2Loader.js';
import { MeshoptDecoder } from 'three/addons/libs/meshopt_decoder.module.js';
const ktx2 = new KTX2Loader()
.setTranscoderPath('/vendor/basis/') // copied from three/examples/jsm/libs/basis/
.detectSupport(renderer);
const loader = new GLTFLoader()
.setMeshoptDecoder(MeshoptDecoder)
.setKTX2Loader(ktx2);
const gltf = await loader.loadAsync('/models/product.opt.glb');
scene.add(gltf.scene);
The decoders are part of the JavaScript budget too, so only include the ones your files actually use. When this loader runs is a separate question: if the scene sits in the hero, it should load after a static poster image has painted, which we cover in how to lazy-load a Three.js scene without hurting LCP.
Make the build fail when the budget is broken
A budget that lives in a document gets ignored by the third design revision. Put it in the repository and check it after every build. This Node script reads limits from a JSON file and fails if any model in the build output is over:
{
"models/hero.opt.glb": 1500000,
"models/product.opt.glb": 4000000,
"default": 2000000
}
// scripts/check-3d-budget.mjs
import fs from 'node:fs';
import path from 'node:path';
const outDir = path.resolve('dist');
const budget = JSON.parse(fs.readFileSync('3d-budget.json', 'utf8'));
const failures = [];
function walk(dir) {
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const full = path.join(dir, entry.name);
if (entry.isDirectory()) walk(full);
else if (/\.(glb|ktx2)$/i.test(entry.name)) {
const rel = path.relative(outDir, full).split(path.sep).join('/');
const limit = budget[rel] ?? budget.default;
const size = fs.statSync(full).size;
if (size > limit) failures.push(`${rel}: ${size} bytes, budget ${limit}`);
}
}
}
walk(outDir);
if (failures.length) {
console.error('3D budget exceeded:\n' + failures.join('\n'));
process.exit(1);
}
console.log('3D assets within budget');
Add it after the build step, for example "build": "astro build && node scripts/check-3d-budget.mjs". The file size is the line you can check automatically. Draw calls and GPU memory need a person with the renderer.info log open on a real phone before each release.
What the budget changes in the brief
The most useful effect of a budget happens before any code. It forces specific conversations with whoever is commissioning the site: how many products the configurator really needs at launch, whether every finish needs its own high resolution texture, whether the hero has to be interactive or can be a short rendered video with a 3D moment further down the page.
Those answers decide cost as much as performance. A scene designed to a budget from day one is cheaper to build than one that has to be cut down after launch because sales reported that the site will not open on a customer’s phone.
If you are planning a 3D or interactive site and want the budget, the asset pipeline and the fallbacks designed together, see our web systems work or tell us about the project.