Per-frame redraw and allocation hot spots (Siege, Maze, sfx noise, pad lookup, Runner HUD, popups, hub loop)

Aperta
#107 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
30/100
Tipo di issue
Refactoring
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
typescript, vite

Direzione di ricerca

This is a bundle of seven separate performance items, so pick one and leave the rest. A good starting point is the Siege shield redraw in games/siege/scenes/GameScene.ts near lines 572-577, using the Maze wall drawing in games/maze/scenes/GameScene.ts (drawWalls) as the pattern. Done means that item is fixed or declined with a before-and-after Performance trace, and the other items are tracked separately.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

help wanted performance severity: low

Summary

A handful of avoidable per-frame costs outside the ones #35 and #37 already track. None is serious alone, but together they add main-thread work and garbage on low-end phones at 60 to 120 Hz. All costs below are estimates from reading the code; nothing was profiled.

Where and what

  • Siege shields and Maze dots redrawn every frame. games/siege/scenes/GameScene.ts:572-577 clears gfx and replays every shield cell as its own fillRect (about 536 rects across 4 shields). games/maze/scenes/GameScene.ts:516-537 does the same for every remaining dot (about 200 fillStyle + fillRect pairs). Both only change on a hit or a dot eaten. Fix: draw them into their own Graphics (Maze already does this for walls in drawWalls) and redraw only when they change.
  • noise() builds a new random AudioBuffer for every sound. shared/sfx.ts:52-66 allocates and fills a buffer with Math.random() on each call. Astro calls it every 90 ms while thrusting (games/astro/scenes/GameScene.ts:246-249) and per rock; Runner every 90 ms while sliding (games/runner/scenes/GameScene.ts:284). That is roughly 170 KB/s of garbage while thrusting. Fix: create one 1 s noise buffer once and play slices with src.start(t, offset, duration).
  • Hub gamepad loop runs forever. src/hub/navigation.ts:227-238 reschedules requestAnimationFrame(poll) unconditionally, even with no gamepad, so the hub never goes idle (battery cost on phones). Fix: start on gamepadconnected (or at load if a pad is already connected) and stop once none remain, as src/hub/pad-bindings.ts:83-101 already does.
  • ArcadeControls.pad rebuilds and sorts the pad list 10 to 20 times a frame. shared/controls.ts:123-131 runs gp.getAll().filter(...).sort(...) on every read, and refresh() and the axis helpers read it repeatedly (shared/controls.ts:185-192, :205-208, :214-235). Fix: resolve the pad once at the top of refresh() and reuse it.
  • Runner re-renders its distance text almost every frame. games/runner/scenes/GameScene.ts:523-532 calls distText.setText from update(), and at 380 to 920 px/s with 12 px per metre the value changes 32 to 77 times a second, each a canvas redraw and texture upload. Fix: use a BitmapText, or update at most every 100 ms. (Related: #36.)
  • Score popups create and destroy a blurred Text each time. shared/ui.ts:34-47 (floatText) makes a new Text with a 12 px shadow blur per popup; Breakout calls it per brick (games/breakout/scenes/GameScene.ts:329) and Astro per rock (games/astro/scenes/GameScene.ts:464), so multiball moments create several at once. Fix: pool a few popup Texts per scene, or use a BitmapText font.
  • Also worth adding to #35: Runner draws drones and the runner with fillRoundedRect / strokeRoundedRect every frame (games/runner/scenes/GameScene.ts:464-466, :505-507, :516-519).

Impact

Frame-time jitter and extra garbage collection on low-end mobile at the busiest moments, and an idle hub that keeps waking the CPU.

Acceptance criteria

  • Each item fixed or explicitly declined, with a before/after Performance trace for the Siege/Maze and hub items.

Getting started

  • Relevant files: listed above
  • How to run tests: npm test; profile with the browser's Performance panel on npm run dev
  • Related: #35, #36, #37

Filed by repo-audit/full-audit at de2b25b. Severity: low. Effort: M. audit-key: performance|games/siege/scenes/GameScene.ts|render

Lingua principale
TypeScript
Stelle
3
Fork
3
Merge medio
10h 22m
PR unite (30g)
6

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TMHSDigital/GH-Arcade

Tutte le issue di TMHSDigital/GH-Arcade

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.