melonjs-performance
Fungsinya
Panduan ini menjelaskan cara mengukur performa dalam game melonJS dan perubahan utama yang mempercepatnya. Panduan ini untuk pengembang game yang game-nya lag atau kehilangan frame.
Kapan dipakai
- βSaat game melonJS seorang pengembang kehilangan frame ketika banyak objek tampil di layar.
- βSaat game seorang pengembang tersendat karena membuat banyak objek setiap frame.
- βSaat seorang pengembang ingin mengukur draw call dan waktu frame sebelum mengoptimalkan.
Link skill
https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-performance/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
βGame melonJS saya lag ketika banyak musuh ada di layar. Bagaimana cara mempercepatnya?β
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Skill meminta AI menambahkan panel debug dan membaca angkanya terlebih dahulu, lalu menyarankan perbaikan seperti memakai texture atlas, mengelompokkan berdasarkan blend mode, dan menggunakan ulang objek.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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
Pertanyaan umum
Apa yang sebaiknya diukur lebih dulu?
Skill menganjurkan panel debug, yang menampilkan waktu frame dan jumlah draw call.
Apa itu batching?
Batching menggabungkan banyak sprite menjadi lebih sedikit draw call, yang biasanya menjadi peningkatan kecepatan terbesar.
Mengapa mengganti blend mode memperlambat?
Skill menyatakan mengganti blend mode mengakhiri batch, sehingga mengelompokkan sprite berdasarkan blend mode membantu.
Detail
Deskripsi asli dari pembuat
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
Popularitas
- Bintang GitHub
- 6.4k
- Peringkat
- #14209
- Lisensi
- MIT
- Diperbarui
- 2/11/2026
Komentar
- β¦
Skill lain dari repositori ini
melonjs-20-migration
6.4kMembantu agent Anda menulis kode game melonJS versi 20 dan menghindari metode yang usang dari versi lama, seperti startup async yang wajib.
melonjs-3d-assets
6.4kMembantu agent Anda memuat model 3D seperti berkas glTF, GLB, dan OBJ ke dalam game browser melonJS, dengan opsi skala dan pencahayaan.
melonjs-3d
6.4kMembantu agent Anda membangun adegan 3D atau 2.5D dalam game browser melonJS, mencakup kamera, mesh, lampu, dan kedalaman, dengan aturan sumbu mesin.
melonjs-audio
6.4kMembantu agent Anda menambahkan efek suara dan musik ke game melonJS, termasuk pengaturan audio, musik latar, kontrol volume, dan suara spasial.
Skill serupa
diffs
394kMemungkinkan agent Anda menghasilkan diff perubahan yang nyata dan dapat dibagikan sebagai tautan viewer atau file gambar, bukan ringkasan yang ditulis manual.
coding-agent
394kMembantu agent Anda menyerahkan pekerjaan pemrograman besar ke Codex, Claude Code, atau OpenCode di latar belakang, lalu memeriksa kemajuannya.
gh-issues
394kMembantu agent Anda menemukan issue GitHub, memilih yang dikerjakan, dan membuka pull request perbaikan, termasuk tindak lanjut komentar tinjauan.