melonjs-performance
Was er macht
Es erklärt, wie man die Leistung eines melonJS-Spiels misst und die wichtigsten Änderungen, die es beschleunigen. Es richtet sich an Spieleentwickler, deren Spiel ruckelt oder Bilder auslässt.
Wann du ihn nutzt
- ✓Wenn das melonJS-Spiel eines Entwicklers Bilder auslässt, weil viele Objekte auf dem Bildschirm sind.
- ✓Wenn das Spiel eines Entwicklers ruckelt, weil es bei jedem Bild viele Objekte erzeugt.
- ✓Wenn ein Entwickler Zeichenaufrufe und Bildzeit messen will, bevor er optimiert.
Link zum Skill
https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-performance/SKILL.mdKopiere ihn und füge ihn in deine KI ein (Claude, ChatGPT oder Cursor) mit der Bitte, den Anweisungen zu folgen.
So nutzt du ihn
Am einfachsten: Kopiere die Nachricht und füge sie in deine KI ein. Sie liest den Skill und folgt den Anweisungen.
Fertige Nachricht zum Einfügen
Für Claude Code, Codex oder Cursor: Führe den Befehl in deinem Projektordner aus, dann wird der Skill installiert.
Lade die SKILL.md herunter und lege sie in den Skills-Ordner deines Agenten.
Beispielanfrage an deine KI
“Mein melonJS-Spiel ruckelt, wenn viele Gegner auf dem Bildschirm sind. Wie kann ich es beschleunigen?”
5 neue Skills pro Woche. 1 Minute Lesezeit.
So funktioniert es
Die Fähigkeit weist den KI-Agenten an, zuerst das Debug-Panel hinzuzufügen und die Werte abzulesen, und schlägt dann Lösungen vor, etwa einen Texturatlas, Gruppierung nach Mischmodus und die Wiederverwendung von Objekten.
Technischer Inhalt (originale SKILL.md)
Originaltext des Autors, auf Englisch, direkt von 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
Häufige Fragen
Was sollte ich zuerst messen?
Die Fähigkeit empfiehlt das Debug-Panel, das Bildzeit und Zeichenaufrufe zeigt.
Was ist Batching?
Batching fasst viele Sprites zu weniger Zeichenaufrufen zusammen, meist der größte Geschwindigkeitsgewinn.
Warum verlangsamt ein Wechsel des Mischmodus alles?
Die Fähigkeit sagt, ein Wechsel des Mischmodus beendet einen Batch, daher hilft es, Sprites nach Mischmodus zu gruppieren.
Details
Originalbeschreibung des Autors
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
Beliebtheit
- GitHub-Sterne
- 6.4k
- Platz im Ranking
- #14209
- Lizenz
- MIT
- Aktualisiert
- 2.11.2026
Kommentare
- …
Weitere Skills aus diesem Repository
melonjs-20-migration
6.4kHilft deinem Agenten, melonJS-Spielcode für Version 20 zu schreiben und veraltete Methoden aus älteren Versionen zu vermeiden, etwa den nun nötigen asynchronen Start.
melonjs-3d-assets
6.4kHilft deinem Agenten, 3D-Modelle wie glTF-, GLB- und OBJ-Dateien in ein melonJS-Browserspiel zu laden, mit Optionen für Maßstab und Beleuchtung.
melonjs-3d
6.4kHilft deinem Agenten, 3D- oder 2,5D-Szenen in einem melonJS-Browserspiel zu bauen, mit Kameras, Meshes, Lichtern und Tiefe, unter Beachtung der eigenen Achsenregeln der Engine.
melonjs-audio
6.4kHilft deinem Agenten, Soundeffekte und Musik in ein melonJS-Spiel einzubauen, einschließlich Audio-Einrichtung, Hintergrundmusik, Lautstärkeregelung und räumlichem Klang.
Ähnliche Skills
diffs
394kLässt deinen Agenten einen echten, teilbaren Diff seiner Änderungen als Viewer-Link oder Bilddatei erstellen, statt einer handgeschriebenen Zusammenfassung.
coding-agent
394kHilft deinem Agenten, eine größere Programmieraufgabe als Hintergrund-Worker an Codex, Claude Code oder OpenCode zu übergeben und danach den Fortschritt zu prüfen.
gh-issues
394kHilft deinem Agenten, GitHub-Issues zu finden, die zu bearbeitenden auszuwählen und Pull Requests mit Korrekturen zu öffnen, einschließlich der Nacharbeit an Review-Kommentaren.