Skip to content

refactor: move per-frame stats collection from AppBase to ApplicationStats#8643

Merged
willeastcott merged 1 commit into
mainfrom
refactor/move-frame-stats-to-application-stats
Apr 23, 2026
Merged

refactor: move per-frame stats collection from AppBase to ApplicationStats#8643
willeastcott merged 1 commit into
mainfrom
refactor/move-frame-stats-to-application-stats

Conversation

@willeastcott

@willeastcott willeastcott commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Relocates the two private per-frame stats collection methods from AppBase onto ApplicationStats, where the counters they populate already live. This is the first of several small, targeted refactors to break up app-base.js (currently ~2k lines, mixing ~10 distinct responsibilities).

  • Moves _fillFrameStatsBasic and _fillFrameStats (~100 lines) out of src/framework/app-base.js and into src/framework/stats.js as ApplicationStats.updateBasic() and ApplicationStats.updateDetailed().
  • AppBase.tick now calls this.stats.updateBasic(currentTime, dt, ms, this.renderer, this.graphicsDevice) and this.stats.updateDetailed(this.renderer, this.graphicsDevice), passing the renderer and graphics device as explicit dependencies rather than the callees reaching back through this.
  • PRIMITIVE_TRIANGLES/PRIMITIVE_TRIFAN/PRIMITIVE_TRISTRIP imports move to stats.js along with the detailed update body.

Public API

No changes. The stats object shape (app.stats.frame.*, app.stats.drawCalls.*, app.stats.particles.*, app.stats.misc.*) is identical. External consumers such as mini-stats continue to work without modification. Both new methods are marked @ignore, matching the visibility of the originals.

File size impact

  • src/framework/app-base.js: 2086 -> 1986 lines (-100)
  • src/framework/stats.js: 133 -> 244 lines (+111)

Test plan

  • npm run lint - clean (0 errors, 1 unrelated pre-existing warning in utils/rollup-build-target.mjs)
  • npm run build:types - types regenerate without errors
  • npm run test:types - passes
  • npm test - 1652 passing, 0 failing (2 pre-existing pending)
  • Spot-check mini-stats example in a local build to confirm frame stats still populate correctly

…Stats

Relocates the two private `_fillFrameStatsBasic` and `_fillFrameStats`
methods (~100 lines) from `AppBase` onto `ApplicationStats` as
`updateBasic()` and `updateDetailed()`. `AppBase.tick` now calls
`this.stats.updateBasic(...)` / `this.stats.updateDetailed(...)` and
passes the renderer and graphics device as explicit dependencies.

Pure internal refactor - no public API changes, no behaviour changes.
The stats object shape (`app.stats.frame.*`, `app.stats.drawCalls.*`,
etc.) is unchanged, so external consumers such as `mini-stats`
continue to work as-is.

Made-with: Cursor

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors per-frame stats collection by moving the basic and profiler-only detailed update logic out of AppBase and into ApplicationStats, aligning the update logic with the counters it populates and reducing responsibilities in app-base.js.

Changes:

  • Added ApplicationStats.updateBasic() and ApplicationStats.updateDetailed() (both @ignore) to encapsulate per-frame stats population and counter resets.
  • Updated AppBase.tick to call the new stats update methods and pass renderer/graphicsDevice as explicit dependencies.
  • Moved primitive-constants imports (PRIMITIVE_TRIANGLES/TRIFAN/TRISTRIP) from app-base.js to stats.js.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/framework/stats.js Adds per-frame stats update methods and relocates the detailed primitive/counter logic into ApplicationStats.
src/framework/app-base.js Replaces internal private stats methods with calls into ApplicationStats, removing duplicated logic and imports.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@willeastcott willeastcott merged commit 2699a9c into main Apr 23, 2026
12 checks passed
@willeastcott willeastcott deleted the refactor/move-frame-stats-to-application-stats branch April 23, 2026 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Request for a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants