본문으로 건너뛰기
Skillpedia
일반 코딩6.4k · #14209

melonjs-performance

하는 일

melonJS 게임의 성능을 측정하는 방법과 속도를 높이는 주요 변경 사항을 설명합니다. 게임이 느리거나 프레임이 떨어지는 게임 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓화면에 오브젝트가 많을 때 개발자의 melonJS 게임에서 프레임이 떨어질 때.
  • ✓개발자의 게임이 매 프레임마다 많은 오브젝트를 만들어서 끊김이 생길 때.
  • ✓개발자가 최적화하기 전에 draw call과 프레임 시간을 측정하려 할 때.

스킬 링크

https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-performance/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-performance/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“적이 많이 화면에 나타나면 제 melonJS 게임이 느려집니다. 어떻게 속도를 높일 수 있나요?”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

스킬은 AI에게 먼저 디버그 패널을 추가해 수치를 읽으라고 안내합니다. 그다음 텍스처 아틀라스 사용, 블렌드 모드별 묶기, 오브젝트 재사용 같은 수정을 제안합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 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 TextureAtlas and prefer one large tileset over several small ones, so a screenful of sprites fits inside the pool with room to spare.
  • Changing blendMode — setBlendMode flushes 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 ShaderEffect on 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:

  • onResetEvent must 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 onDestroyEvent on removal. Removal always calls onDeactivateEvent, then tries to return the object to the pool that built it; only when nothing owns it does it fall through to destroy(), which is what calls onDestroyEvent. So a successfully recycled object never sees it. Pair event subscriptions with onActivateEvent / onDeactivateEvent instead, or you leak handlers.

  • removeChild is 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 throws Child is not mine. Take it out immediately instead, keeping the instance alive for reuse:

    world.removeChildNow(bullet, true);   // keepalive: do NOT destro
    
자주 묻는 질문

무엇을 먼저 측정해야 하나요?

프레임 시간과 draw call을 보여 주는 디버그 패널을 권장합니다.

배칭이란 무엇인가요?

많은 스프라이트를 더 적은 draw call로 묶는 것이며, 보통 가장 큰 속도 향상을 줍니다.

블렌드 모드를 바꾸면 왜 느려지나요?

블렌드 모드를 바꾸면 배치가 끊기므로, 스프라이트를 블렌드 모드별로 묶는 것이 도움이 된다고 스킬은 말합니다.

상세 정보

작성자의 원본 설명

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

인기도

GitHub 스타
6.4k
순위
#14209
라이선스
MIT
업데이트
2026. 11. 2.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬