melonjs-performance
Ce qu’il fait
Ce guide explique comment mesurer les performances d'un jeu melonJS et les principales modifications qui l'accélèrent. Il s'adresse aux développeurs de jeux dont le jeu ralentit ou perd des images.
Quand l’utiliser
- ✓Quand le jeu melonJS d'un développeur perd des images lorsque beaucoup d'objets sont à l'écran.
- ✓Quand le jeu d'un développeur saccade parce qu'il crée de nombreux objets à chaque image.
- ✓Quand un développeur veut mesurer les appels de dessin et le temps par image avant d'optimiser.
Lien du skill
https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-performance/SKILL.mdCopiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.
Comment l’utiliser
Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.
Message prêt à coller
Pour Claude Code, Codex ou Cursor : lancez-la dans le dossier du projet et le skill est installé.
Téléchargez le SKILL.md et placez-le dans le dossier de skills de votre agent.
Exemple de demande à votre IA
“Mon jeu melonJS ralentit quand il y a beaucoup d'ennemis à l'écran. Comment l'accélérer ?”
5 nouveaux skills par semaine. 1 minute de lecture.
Comment ça marche
Le skill demande à l'IA d'ajouter le panneau de débogage et de lire d'abord les chiffres, puis propose des corrections comme l'utilisation d'un atlas de textures, le regroupement par mode de fusion et la réutilisation des objets.
Contenu technique (SKILL.md original)
Texte original de l’auteur, en anglais, directement depuis GitHub.
Performance
Measure first
Register the debug plugin and read the numbers before changing anything:
import { plugin } from "melonjs";
import { DebugPanelPlugin } from "@melonjs/debug-plugin";
await app.init();
plugin.register(DebugPanelPlugin, "debugPanel");
It reports frame time, draw calls, object counts, and can overlay collision shapes and bounds. Draw calls is usually the number that matters.
Batching: the biggest lever
Both GPU backends batch across textures, not just within one: the quad
batcher assigns each source image a texture unit and embeds the unit in the
vertex data, so several different images still flush as a single draw. The pool
is finite — the WebGL batcher gets renderer.maxTextures units (the
maxTextures application setting, "auto" = the device limit capped at 32), the
WebGPU batcher eight per segment. Overflow the pool and the batch flushes.
So the goal is not "one image" but "few state changes". What actually ends a batch:
- Overflowing the texture-unit pool — pack sprites into a
TextureAtlasand prefer one large tileset over several small ones, so a screenful of sprites fits inside the pool with room to spare. - Changing
blendMode—setBlendModeflushes before it touches GL state. Group by blend mode where you can. - Switching batcher — interleaving primitives (
strokeRect,fillRect, debug shapes) or meshes between sprites flushes the quad batcher and rebinds. Draw all the sprites, then all the primitives. - Binding a custom shader — a
ShaderEffecton the quad batcher also turns multi-texture batching off for the duration, dropping you back to one texture per draw.
The advanced blend modes are the expensive ones: overlay, difference,
hard-light, soft-light, color-dodge, color-burn, darken and lighten
cannot be expressed as fixed-function blending, so each such draw is bracketed
on its own — capture the destination, redraw offscreen, composite through a
shader. Right for accents, wrong for hundreds of objects. normal, additive,
multiply, screen and exclusion are plain fixed-function state and cost
nothing extra.
Pooling
Anything spawned frequently — bullets, particles, pickups, damage numbers — should be pooled rather than allocated:
import { createPool } from "melonjs";
const bulletPool = createPool((x, y) => {
const instance = new Bullet(x, y);
return { instance, reset: (x, y) => instance.onResetEvent(x, y) };
});
const b = bulletPool.get(x, y); // recycled: reset(x, y)
// fresh: new Bullet(x, y)
world.removeChild(b); // returns to bulletPool automatically
The container returns a child to whichever pool built it, so removal is enough;
you only call release() yourself for something that was never added to the
world.
me.pool is the older, string-keyed version and is deprecated since
18.0.0. pool.register(name, Class, true) / pool.pull(name) still work and
print a one-off console notice, but a recycled object is no longer returned on
removal, so pooling through it now costs an allocation per spawn. To register a
class so a Tiled map can name it, use registerTiledObjectClass — that is a
separate registry and is not deprecated.
Two rules that cause subtle bugs when missed:
onResetEventmust restore everything the object's lifetime mutates — alpha, tint, scale, animation, velocity. Anything you forget carries into the next use, which looks like a random visual glitch.Pooled objects do not fire
onDestroyEventon removal. Removal always callsonDeactivateEvent, then tries to return the object to the pool that built it; only when nothing owns it does it fall through todestroy(), which is what callsonDestroyEvent. So a successfully recycled object never sees it. Pair event subscriptions withonActivateEvent/onDeactivateEventinstead, or you leak handlers.removeChildis DEFERRED, which breaks a pool you re-lend in the same frame. The removal is queued and runs after the update and draw stack has unwound, so an object you remove and immediately hand out again is torn out from under its new owner when the queue drains: it vanishes, and the frame after that the removal throwsChild is not mine.Take it out immediately instead, keeping the instance alive for reuse:world.removeChildNow(bullet, true); // keepalive: do NOT destro
Questions fréquentes
Que faut-il mesurer en premier ?
Le skill recommande le panneau de débogage, qui affiche le temps par image et les appels de dessin.
Qu'est-ce que le regroupement ?
Le regroupement combine de nombreux sprites en moins d'appels de dessin, ce qui offre généralement le plus grand gain de vitesse.
Pourquoi changer de mode de fusion ralentit-il le jeu ?
Le skill indique que changer de mode de fusion termine un lot, donc regrouper les sprites par mode de fusion aide.
Détails
Description originale de l’auteur
Use this skill when a melonJS game drops frames, allocates heavily, or needs to scale to many objects. Covers object pooling, draw-call batching, atlases, baking with CanvasRenderTarget, instancing, culling and alwaysUpdate, the debug plugin, and where the real costs are. Triggers on: performance, slow, frame rate, fps, lag, pool, pool.register, pool.pull, batching, draw calls, InstancedMesh, culling, alwaysUpdate, inViewport, CanvasRenderTarget, optimise, profiling, debug plugin, memory, render targets, hdr.
repo: melonjs/melonJS
Popularité
- Étoiles GitHub
- 6.4k
- Position au classement
- #14209
- Licence
- MIT
- Mis à jour
- 02/11/2026
Commentaires
- …
Autres skills de ce dépôt
melonjs-20-migration
6.4kAide votre agent à écrire du code de jeu melonJS pour la version 20 et à éviter les méthodes obsolètes des versions précédentes, comme le démarrage asynchrone obligatoire.
melonjs-3d-assets
6.4kAide votre agent à charger des modèles 3D comme les fichiers glTF, GLB et OBJ dans un jeu melonJS, avec des options d'échelle et d'éclairage.
melonjs-3d
6.4kAide votre agent à construire des scènes 3D ou 2,5D dans un jeu melonJS, avec les caméras, les maillages, les lumières et la profondeur, selon les règles d'axes du moteur.
melonjs-audio
6.4kAide votre agent à ajouter des effets sonores et de la musique à un jeu melonJS, avec la configuration audio, les pistes de fond, le réglage du volume et le son spatial.
Skills similaires
diffs
394kPermet à votre agent de produire un diff réel et partageable de vos modifications, sous forme de lien ou d'image, plutôt qu'un résumé écrit à la main.
coding-agent
394kAide votre agent à confier une tâche de programmation plus importante à Codex, Claude Code ou OpenCode comme travailleur en arrière-plan, puis à suivre sa progression.
gh-issues
394kAide votre agent à trouver des tickets GitHub, choisir ceux à traiter et ouvrir des pull requests avec des correctifs, y compris le suivi des commentaires de relecture.