Bash.tv → GitHub → itch.io

Reuse game objects (bullets, particles, enemies, pickups, popups, sounds) instead of creating and throwing them away, so garbage collection doesn't cause stutters. A tested Pool with prewarming, a max size, reset hooks, O(1) swap-remove during iteration and stats, plus a ring buffer for overwrite-oldest effects. Covers what to pool, resetting state fully, pooling in Phaser and three.js, and mea...

Download skill (.zip) Files on GitHub

Game object pooling

Creating thousands of short-lived objects per second makes the garbage collector pause the game (stutters every few seconds, worse on phones). Pool anything that spawns often and dies soon. Drop-in: assets/pool.js (tested).

import { Pool, Ring } from "./core/pool.js";
const bullets = new Pool(() => ({ x: 0, y: 0, vx: 0, vy: 0, life: 0, hit: false }), {
  prewarm: 200, max: 500,                                     // allocate at load, cap at 500 live
  reset: (b) => { b.hit = false; },                           // clear EVERY field that matters, or old state leaks
});
bullets.spawn((b) => { b.x = px; b.y = py; b.vx = 600; b.vy = 0; b.life = 1.2; });   // returns null at max
bullets.update((b) => { b.x += b.vx * dt; return (b.life -= dt) > 0 && !b.hit; });    // false → back to the pool
bullets.forEach((b) => ctx.fillRect(b.x - 2, b.y - 2, 4, 4));
bullets.releaseAll();                                          // on restart / level end
const sparks = new Ring(300, () => ({ x: 0, y: 0, life: 0 }));  // particles: overwrite the oldest, never allocate

update walks backwards and swap-removes, so removing during iteration never skips an item (the classic forward-splice bug).

What to pool

Pool Don’t bother
Bullets, particles, sparks, damage numbers, coins, enemies in waves, explosions, trails, decals, audio voices The player, bosses, level geometry, UI screens, things created once per level

Rules

Engines

Prove it

Profile before and after (game-performance-profiling): heap peak − start should drop, and p99 frame time with it. “Heap churn 9 MB/s → 0.3 MB/s; p99 31 → 17 ms.”