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

未关闭
#107 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
30/100
Issue 类型
重构
描述清晰度
基本清楚
活跃度
活跃
技术栈
typescript, vite

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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

主要语言
TypeScript
星标
3
派生
3
平均合并
10 小时 22 分钟
30 天内合并 PR
6

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

TMHSDigital/GH-Arcade 的其他 Issue

查看 TMHSDigital/GH-Arcade 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。