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

オープン
#141 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
72/100
issue の種類
リファクタリング
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
typescript

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
TypeScript
スター
3
フォーク
3
平均マージ
10時間 22分
マージ済み PR(30日)
6

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

TMHSDigital/GH-Arcade のほかの issue

TMHSDigital/GH-Arcade の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。