Runner sun, Snake bonus star and Stack previews allocate every frame

Aperta
#141 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
72/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript

Direzione di ricerca

Read the render paths in games/runner/scenes/GameScene.ts and games/snake/scenes/GameScene.ts, then inspect drawMini in games/stack/scenes/GameScene.ts. Compare the per-frame allocations with the suggested caching or reuse approaches in the issue. Run npm test and use npm run dev to check the three screens; done means all three paths avoid per-frame allocations while their visuals stay unchanged.

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

Descrizione

good first issue performance severity: low

Summary

Three render paths allocate new objects on every frame for values that do not change from frame to frame. Each one is small, but together they add steady garbage on phones.

Where

  • games/runner/scenes/GameScene.ts (render, the synthwave sun): each frame builds two Phaser.Display.Color objects with ValueToColor and interpolates a third for each of the 12 sun bands, although the band colors never change.
  • games/snake/scenes/GameScene.ts (starPoints, called from render while a bonus star is up): a new array of 10 Phaser.Math.Vector2 each frame.
  • games/stack/scenes/GameScene.ts (drawMini): for the hold piece and every next-piece preview, each frame builds a cell array and four mapped arrays for Math.min / Math.max, although a piece type's preview layout never changes.

Details

Runner's sun, for example:

const c = Phaser.Display.Color.Interpolate.ColorWithColor(
  Phaser.Display.Color.ValueToColor(NEON.yellow),
  Phaser.Display.Color.ValueToColor(NEON.pink),
  11,
  i,
);

Impact

Low. This is extra minor-GC pressure for as long as each screen is up. It is the same class of cost as the items in #107.

Suggested fix

  • Runner: compute the 12 band colors once into a module constant.
  • Snake: reuse one points array and set its entries in place, or bake the star once (the rotation could then be the Image's rotation).
  • Stack: cache each piece type's preview cells and offsets in a Map the first time it is drawn.

Acceptance criteria

  • None of the three paths allocates per frame.
  • Visuals are unchanged.

Getting started

  • Relevant files: the three scenes above
  • How to run tests: npm test; run a game with npm run dev

Related: #107


Filed by repo-audit/fix-issues at b2a3ff6. Severity: low. Effort: S. audit-key: performance|games/runner/scenes/GameScene.ts|sun-colors

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.