mobile-performance-budget
БесплатноБез исполняемых скриптовНе проверенMake a three.js scene hold frame rate on phones: measure draw calls, triangles, texture memory and frame time with renderer.info and THREE.Timer, cut draw…
от nirholas★ 289 звёзд на GitHubОб этом скилле
A mobile performance budget for three.js
Targets three.js r187 ([email protected]). Every runnable block is executed in Chromium against
a real CC0 model before this plugin ships.
Measure first. Phones are usually limited by one of four things, and each has a different fix:
| Limit | Measure with | Typical mid-range phone budget | Main fixes |
|---|---|---|---|
| Draw calls (CPU) | renderer.info.render.calls |
under 100 to 150 per frame | InstancedMesh, BatchedMesh, merging, fewer materials |
| Pixels (GPU fill rate) | frame time vs pixel ratio | pixel ratio 1.5 to 2 at most | setPixelRatio(Math.min(devicePixelRatio, 2)), adaptive resolution, fewer full-screen passes |
| Triangles (GPU vertex work) | renderer.info.render.triangles |
100k to 500k visible | LOD, simplify, cull |
| Texture memory (crashes on iOS) | estimate below; renderer.info.memory.textures |
under 100 to 200 MB of GPU texture | KTX2/Basis, 1024 or 2048 maps, share textures |
Phones run at 60 or 120 Hz, so the frame budget is 16.7 ms or 8.3 ms, and a phone that throttles under heat loses a third of that. Target your heaviest view at well under budget on a mid-range Android device, not your laptop.
1. A measuring HUD, and instancing a glTF model
This builds 100 copies of the model two ways, as clones and as one InstancedMesh per mesh
in the model, measures both, and leaves the instanced version running with a live HUD.
renderer.info resets on every render(), so read it right after rendering. Press C to
switch to the clones and watch the draw calls jump.
import * as THREE from 'three';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';
const MAX_PIXEL_RATIO = Math.min(window.devicePixelRatio, 2);
const renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: 'high-performance' });
renderer.setPixelRatio(MAX_PIXEL_RATIO);
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.toneMapping = THREE.AgXToneMapping;
document.body.appendChild(renderer.domElement);
const hud = document.createElement('pre');
hud.style.cssText = 'position:fixed;left:8px;top:8px;margin:0;padding:8px 10px;font:12px/1.4 ui-monospace,monospace;color:#e8eaed;background:rgba(0,0,0,.6);border-radius:6px;pointer-events:none';
document.body.appendChild(hud);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x24272e);
scene.environment = new THREE.PMREMGenerator(renderer).fromScene(new RoomEnvironment(), 0.04).texture;
const gltf = await new GLTFLoader().loadAsync('model.glb');
const model = gltf.scene;
model.updateMatrixWorld(true);
const size = new THREE.Box3().setFromObject(model).getSize(new THREE.Vector3());
const spacing = Math.max(size.x, size.z) * 1.4;
const GRID = 10; // 100 copies
const placements = [];
for (let x = 0; x < GRID; x++) {
for (let z = 0; z < GRID; z++) {
const m = new THREE.Matrix4().makeRotationY(((x * 7 + z * 13) % 8) * (Math.PI / 4));
m.setPosition((x - (GRID - 1) / 2) * spacing, 0, (z - (GRID - 1) / 2) * spacing);
placements.push(m);
}
}
// Slow path: every clone is its own set of draw calls.
const clones = new THREE.Group();
for (const m of placements) {
const copy = model.clone(); // shares geometry and materials, still one draw call per mesh per copy
copy.applyMatrix4(m);
clones.add(copy);
}
// Fast path: one InstancedMesh per mesh in the model, one draw call each for all 100 copies.
const instanced = new THREE.Group();
model.traverse((mesh) => {
if (!mesh.isMesh) return;
const inst = new THREE.InstancedMesh(mesh.geometry, mesh.material, placements.length);
const local = mesh.matrixWorld; // the mesh's transform inside the model
placements.forEach((m, i) => inst.setMatrixAt(i, new THREE.Matrix4().multiplyMatrices(m, local)));
inst.instanceMatrix.needsUpdate = true;
inst.computeBoundingSphere(); // covers all instances, so frustum culling stays correct
instanced.add(inst);
});
const extent = spacing * GRID;
const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, spacing / 20, extent * 4);
camera.position.set(extent * 0.55, extent * 0.4, extent * 0.75);
camera.lookAt(0, 0, 0);
function measure(group) {
scene.add(group);
renderer.render(scene, camera);
const { calls, triangles } = renderer.info.render;
scene.remove(group);
return { calls, triangles };
}
const cloneCost = measure(clones);
const instancedCost = measure(instanced);
// Upper bound for uncompressed RGBA8 textures with mipmaps. KTX2 textures are 4 to 8 times smaller.
function textureMegabytes(root) {
const seen = new Set();
let bytes = 0;
root.traverse((obj) => {
for (const material of [].concat(obj.material || [])) {
for (const value of Object.values(material)) {
if (!value?.isTexture || seen.has(value)) continue;
seen.add(value);
const { width = 0, height = 0 } = value.image || {};
bytes += width * height * 4 * (value.gener
Установить mobile-performance-budget в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл mobile-performance-budget?
Make a three.js scene hold frame rate on phones: measure draw calls, triangles, texture memory and frame time with renderer.info and THREE.Timer, cut draw calls with InstancedMesh and BatchedMesh, cap the pixel ratio and scale resolution adaptively, shrink texture memory with KTX2 and smaller maps, and stay inside a concrete per-frame budget. Use when a scene is slow, janky, hot, drains battery, crashes or reloads on iOS Safari, stutters on Android, has too many draw calls, repeats the same object many times, or when the user asks how to profile or optimize three.js performance.
Как установить скилл mobile-performance-budget?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл mobile-performance-budget запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic