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

Abierto
#141 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
72/100
Tipo de issue
Refactorización
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
typescript

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
TypeScript
Estrellas
3
Forks
3
Merge medio
10 h 22 min
PR fusionados (30 d)
6

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de TMHSDigital/GH-Arcade

Todos los issues de TMHSDigital/GH-Arcade

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.