Bash.tv → GitHub → itch.io

Make browser games run smoothly on phones. A first guess at the device's power (cores, memory, phone or desktop, data saver) with low, mid and high quality presets, an automatic quality governor that lowers render resolution when frames drop and raises it carefully without flickering, refresh-rate detection (30, 60, 120 Hz), frame time statistics with jank counts, an on-screen FPS readout for r...

Download skill (.zip) Files on GitHub

Mobile performance

Phones have a fraction of a desktop’s power, a lot of pixels, and they slow down when they get warm. The biggest wins on mobile, in order:

  1. Fewer pixels. Cap the device pixel ratio at 2 (or 1.5 on weak phones) and lower the render scale when frames drop. A 3x phone at full density draws 9 times the pixels of 1x. (fullscreen-management backingSize)
  2. Less overdraw. Big transparent layers, full-screen glow and many stacked sprites cost fill rate. Draw the background once into an offscreen canvas; skip invisible layers (canvas-performance, webgl-performance).
  3. Fewer objects created per frame. Garbage collection pauses show up as jank (game-object-pooling).
  4. Fewer draw calls and state changes (sprite sheets, batching).
  5. Sleep when idle and pause when hidden (game-battery-optimization).

assets/mobile-perf.js

import { deviceTier, QUALITY, createGovernor, frameStats, detectRefresh, capDt, pauseWhenHidden, drawPerfOverlay } from "./mobile-perf.js";
const { tier, quality, reasons } = deviceTier();           // first guess: "low" | "mid" | "high"
particles.max = 400 * quality.particles; shadows = quality.shadows;
const gov = createGovernor({ target: 60, onChange: (scale) => resize(scale) });   // render scale steps 1, 0.85, 0.7, 0.55
const stats = frameStats();
loop: const dt = capDt(rawDt); stats.push(rawDt); gov.frame(rawDt); ...; if (debug) drawPerfOverlay(ctx, stats, gov);
pauseWhenHidden({ pause, resume });

Measure on a real phone

The sandbox and desktop emulation don’t show phone speed. Turn on the overlay (?debug in the URL), play for two minutes (phones slow down when warm), and note fps, p95 and jank. In the Bash preview, ask the viewer to open it on their phone; for WebGL games use check_gpu_render for a rough check only. Targets: p95 under 20 ms at 60 Hz, almost no frames over 33 ms.

Memory

Phones kill tabs that use too much memory (often 300-500 MB on iPhone, less on cheap Android): keep decoded images small (a 4096x4096 texture is 64 MB), unload level assets, and test long sessions (game-memory-leak-detection).

Tested

Node tests: device tiers for weak and strong devices, the governor holding at 60 fps, dropping after a slow stretch, rising after a good one, not flickering, ignoring the loading frames; refresh detection; frame statistics; dt capping; pause on hidden and page hide. The device lab (cross-browser-compatibility) has a stress test that makes the governor step down: try it on a phone.

Pitfalls

Testing only on a desktop, full device pixel ratio on phones, a quality governor that flips back and forth, judging speed in the first second, ignoring heat over a longer session, and no way for players to choose lower quality.