Skip to content

Adapt Stats to use engine RenderingStatistics and remove inaccurate hooks#345

Merged
cptbtptpbcptdtptp merged 8 commits intogalacean:dev/2.0from
GuoLei1990:add-stat-vram
Mar 4, 2026
Merged

Adapt Stats to use engine RenderingStatistics and remove inaccurate hooks#345
cptbtptpbcptdtptp merged 8 commits intogalacean:dev/2.0from
GuoLei1990:add-stat-vram

Conversation

@GuoLei1990
Copy link
Member

@GuoLei1990 GuoLei1990 commented Mar 1, 2026

image

Summary

  • Adapt Stats panel to read GPU memory data (textureMemory, bufferMemory, totalMemory) from engine.renderingStatistics
  • Simplify constructor chain to only pass engine instead of raw gl context
  • Remove inaccurate/incomplete WebGL hooks: TextureHook, ShaderHook, RequestHook
  • Upgrade peerDependency to @galacean/engine >= 2.0.0-0

Changes

  • Core.ts: Accept Engine instead of gl, read renderingStatistics for memory stats, remove texture/shader/request hook usage
  • Monitor.ts: Add Total Graphics Memory, Texture Memory, Buffer Memory to panel; rename "Memory" to "JS Memory"; remove Textures, Shaders, Network Size entries
  • Stats.ts: Simplify _setupMonitor() to pass this.engine directly; remove hookRequest static method and camera field
  • Deleted: TextureHook.ts, ShaderHook.ts, RequestHook.ts
  • README.md: Update features list to reflect new memory stats and removed items
  • package.json: Bump peerDependency from >=1.6.0-0 to >=2.0.0-0

Test plan

  • Verify Stats panel displays FPS, JS Memory, Total Graphics Memory, Texture Memory, Buffer Memory, DrawCall, Triangles, WebGL
  • Verify memory values update correctly from engine.renderingStatistics
  • Verify no TypeScript compilation errors

Summary by CodeRabbit

  • Breaking Changes

    • Updated minimum engine version requirement to 2.0.0+
    • Changed stats initialization to use Engine instance instead of WebGL context
  • New Features

    • Added new memory metrics: JS Memory, Graphics Memory, Texture Memory, and Buffer Memory
  • Removed Features

    • Removed shader and texture count tracking
    • Removed network request size monitoring
    • Removed detailed draw call breakdown metrics

@GuoLei1990 GuoLei1990 added the enhancement New feature or request label Mar 1, 2026
@coderabbitai
Copy link

coderabbitai bot commented Mar 1, 2026

Warning

Rate limit exceeded

@GuoLei1990 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 12 minutes and 29 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 883f5a62-7351-4b28-a8b1-a62a78d39acd

📥 Commits

Reviewing files that changed from the base of the PR and between 15cb661 and 958d788.

📒 Files selected for processing (18)
  • packages/auxiliary-lines/package.json
  • packages/controls/package.json
  • packages/custom-gltf-parser/package.json
  • packages/custom-material/package.json
  • packages/draco/package.json
  • packages/dynamic-bone/package.json
  • packages/framebuffer-picker/package.json
  • packages/geometry-sketch/package.json
  • packages/gizmo/package.json
  • packages/input-logger/package.json
  • packages/lines/package.json
  • packages/navigation-gizmo/package.json
  • packages/outline/package.json
  • packages/skeleton-viewer/package.json
  • packages/tween/package.json
  • packages/way-point/package.json
  • packages/xr/package.json
  • tests/package.json

Walkthrough

The stats package is refactored to use the Engine instance directly instead of WebGL context. Hook-based instrumentation (TextureHook, ShaderHook, RequestHook) is removed, replaced with metrics derived from engine.renderingStatistics. Peer dependency constraint bumped to @galacean/engine >=2.0.0-0.

Changes

Cohort / File(s) Summary
Documentation & Configuration
packages/stats/README.md, packages/stats/package.json, package.json
Updated feature list with new memory metrics (JS Memory, totalGraphicsMemory, textureMemory, bufferMemory); removed CPU memory and draw-call details. Bumped @galacean/engine peer dependency from >=1.6.0-0 to >=2.0.0-0.
Core Stats Architecture
packages/stats/src/Core.ts, packages/stats/src/Monitor.ts, packages/stats/src/Stats.ts
Constructor signatures changed to accept Engine instance instead of WebGL context. Removed camera-based initialization and static hookRequest method. PerformanceData interface updated to expose new memory metrics from engine.renderingStatistics instead of hook-tracked values.
Removed Hook Modules
packages/stats/src/hooks/RequestHook.ts, packages/stats/src/hooks/ShaderHook.ts, packages/stats/src/hooks/TextureHook.ts
Entire hook implementations deleted. RequestHook (XHR instrumentation), ShaderHook (shader attachment tracking), and TextureHook (texture allocation tracking) are no longer used; metrics now sourced from Engine's built-in statistics.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Hooks are gone, the Engine takes the lead,
Statistics flow from where we truly need,
Memory metrics shine in proper form,
A cleaner stats design becomes the norm!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main changes: adapting Stats to use engine RenderingStatistics and removing outdated hooks.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
packages/stats/src/Core.ts (2)

62-66: Return type inconsistency: function returns undefined without explicit return.

The update() method has return type PerformanceData but returns undefined implicitly on lines 65-67 and 70-73. Consider using PerformanceData | undefined as the return type for clarity.

Proposed fix
-  public update(): PerformanceData {
+  public update(): PerformanceData | undefined {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/stats/src/Core.ts` around lines 62 - 66, The update() method in
Core.ts has a declared return type of PerformanceData but can return undefined
early; change the signature of update() from returning PerformanceData to
PerformanceData | undefined (or alternatively ensure it always returns a
PerformanceData), update any callers accordingly, and keep the existing
early-return branches that currently return nothing; this affects the update()
method and related uses of its return value (e.g., places that read its result),
so update those call sites to handle the undefined case.

28-34: Accessing internal API via @ts-ignore is fragile.

engine._hardwareRenderer.gl is an internal implementation detail that may change without notice. Consider requesting an official public API from the engine team to access the WebGL context, or document this as a known limitation.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/stats/src/Core.ts` around lines 28 - 34, The constructor currently
reaches into a private field (engine._hardwareRenderer.gl) using `@ts-ignore`
which is fragile; instead add a safe public-facing approach: change the Core
constructor signature to accept an optional WebGLRenderingContext/GLContext
parameter (e.g., constructor(engine: Engine, gl?: WebGLRenderingContext |
WebGL2RenderingContext)), prefer using a hypothetical public accessor like
engine.getGL() if it exists, and only fall back to engine._hardwareRenderer.gl
when no public API or passed-in gl is available while logging/documenting this
fallback; update references in the constructor (the Engine param, the gl
assignment, and the call to this.hook(gl)) and remove the `@ts-ignore` so
consumers can inject a stable GL or the engine team can add a public getter
later.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/stats/src/Core.ts`:
- Line 77: The compiler error comes from accessing
this.engine.renderingStatistics and its fields (textureMemory, bufferMemory,
totalMemory) while the installed `@galacean/engine` types don't declare
renderingStatistics; fix by either updating the dependency to a release that
includes the renderingStatistics type (verify and bump `@galacean/engine` to the
correct version) or make the access type-safe: in Core.ts check/guard that
this.engine.renderingStatistics exists (use optional chaining and fallback
defaults) or add a local type augmentation for the Engine instance (declare the
renderingStatistics interface with textureMemory/bufferMemory/totalMemory) and
cast this.engine appropriately before reading those properties so TypeScript no
longer complains.

---

Nitpick comments:
In `@packages/stats/src/Core.ts`:
- Around line 62-66: The update() method in Core.ts has a declared return type
of PerformanceData but can return undefined early; change the signature of
update() from returning PerformanceData to PerformanceData | undefined (or
alternatively ensure it always returns a PerformanceData), update any callers
accordingly, and keep the existing early-return branches that currently return
nothing; this affects the update() method and related uses of its return value
(e.g., places that read its result), so update those call sites to handle the
undefined case.
- Around line 28-34: The constructor currently reaches into a private field
(engine._hardwareRenderer.gl) using `@ts-ignore` which is fragile; instead add a
safe public-facing approach: change the Core constructor signature to accept an
optional WebGLRenderingContext/GLContext parameter (e.g., constructor(engine:
Engine, gl?: WebGLRenderingContext | WebGL2RenderingContext)), prefer using a
hypothetical public accessor like engine.getGL() if it exists, and only fall
back to engine._hardwareRenderer.gl when no public API or passed-in gl is
available while logging/documenting this fallback; update references in the
constructor (the Engine param, the gl assignment, and the call to this.hook(gl))
and remove the `@ts-ignore` so consumers can inject a stable GL or the engine team
can add a public getter later.

ℹ️ Review info

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b89bb15 and b792255.

📒 Files selected for processing (5)
  • packages/stats/README.md
  • packages/stats/package.json
  • packages/stats/src/Core.ts
  • packages/stats/src/Monitor.ts
  • packages/stats/src/Stats.ts

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/draco/package.json`:
- Around line 22-24: The package.json currently lists "@galacean/engine" under
"dependencies"; move it into "peerDependencies" instead to match the monorepo
toolkit convention and avoid bundling a duplicate engine. Remove the
"@galacean/engine" entry from "dependencies" and add the same version constraint
(">=2.0.0-0") under "peerDependencies"; if the package needs the engine at
build/test time, also add a matching entry under "devDependencies" to satisfy
local tooling.

In `@packages/stats/src/Monitor.ts`:
- Around line 68-69: The array initialization for Monitor.items is duplicated
and formatted in a way that triggers prettier; remove the redundant this.items =
[] assignment and replace the single-line array with a properly formatted array
literal assigned to this.items (keep the existing values "fps", "memory",
"totalGraphicsMemory", "textureMemory", "bufferMemory", "drawCall", "triangles",
"webglContext") inside the Monitor constructor or initializer so the assignment
is singular and conforms to prettier formatting for arrays.

ℹ️ Review info

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 61fd1f50-b43e-4bc6-8334-2cd0240a0b4b

📥 Commits

Reviewing files that changed from the base of the PR and between b792255 and a389f4d.

📒 Files selected for processing (26)
  • package.json
  • packages/auxiliary-lines/package.json
  • packages/controls/package.json
  • packages/custom-gltf-parser/package.json
  • packages/custom-material/package.json
  • packages/draco/package.json
  • packages/dynamic-bone/package.json
  • packages/framebuffer-picker/package.json
  • packages/geometry-sketch/package.json
  • packages/gizmo/package.json
  • packages/input-logger/package.json
  • packages/lines/package.json
  • packages/navigation-gizmo/package.json
  • packages/outline/package.json
  • packages/skeleton-viewer/package.json
  • packages/stats/README.md
  • packages/stats/src/Core.ts
  • packages/stats/src/Monitor.ts
  • packages/stats/src/Stats.ts
  • packages/stats/src/hooks/RequestHook.ts
  • packages/stats/src/hooks/ShaderHook.ts
  • packages/stats/src/hooks/TextureHook.ts
  • packages/tween/package.json
  • packages/way-point/package.json
  • packages/xr/package.json
  • tests/package.json
💤 Files with no reviewable changes (3)
  • packages/stats/src/hooks/RequestHook.ts
  • packages/stats/src/hooks/TextureHook.ts
  • packages/stats/src/hooks/ShaderHook.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/auxiliary-lines/package.json

Comment on lines 22 to 24
"dependencies": {
"@galacean/engine": ">=1.6.0-0"
"@galacean/engine": ">=2.0.0-0"
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check `@galacean/engine` declarations in all package.json files

echo "=== Checking `@galacean/engine` declarations across all packages ===" 
echo ""

fd -e json -g 'package.json' packages | sort | while read pkgfile; do
  # Extract package name and dependencies info
  pkgname=$(cat "$pkgfile" | jq -r '.name // "unknown"')
  
  # Check for `@galacean/engine` in dependencies
  dep_version=$(cat "$pkgfile" | jq -r '.dependencies["@galacean/engine"] // "NOT DECLARED"')
  
  # Check for `@galacean/engine` in peerDependencies  
  peer_version=$(cat "$pkgfile" | jq -r '.peerDependencies["@galacean/engine"] // "NOT DECLARED"')
  
  echo "Package: $pkgname (file: $pkgfile)"
  echo "  dependencies:       $dep_version"
  echo "  peerDependencies:   $peer_version"
  echo ""
done

Repository: galacean/engine-toolkit

Length of output: 3079


Move @galacean/engine from dependencies to peerDependencies.

This package declares @galacean/engine as a regular dependency, but all other toolkit packages in the monorepo use peerDependencies. For toolkit packages that integrate with a host application's engine instance, peerDependencies is the standard to avoid duplicate engine instances and version conflicts at runtime.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/draco/package.json` around lines 22 - 24, The package.json currently
lists "@galacean/engine" under "dependencies"; move it into "peerDependencies"
instead to match the monorepo toolkit convention and avoid bundling a duplicate
engine. Remove the "@galacean/engine" entry from "dependencies" and add the same
version constraint (">=2.0.0-0") under "peerDependencies"; if the package needs
the engine at build/test time, also add a matching entry under "devDependencies"
to satisfy local tooling.

Comment on lines 68 to +69
this.items = [];
this.items = ["fps", "memory", "drawCall", "triangles", "textures", "shaders", "size", "webglContext"];
this.items = ["fps", "memory", "totalGraphicsMemory", "textureMemory", "bufferMemory", "drawCall", "triangles", "webglContext"];
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix prettier failure in items initialization.

Line 69 is flagged by prettier/prettier. Reformatting this array (and removing the redundant initial assignment) should clear the lint error.

💡 Proposed fix
-    this.items = [];
-    this.items = ["fps", "memory", "totalGraphicsMemory", "textureMemory", "bufferMemory", "drawCall", "triangles", "webglContext"];
+    this.items = [
+      "fps",
+      "memory",
+      "totalGraphicsMemory",
+      "textureMemory",
+      "bufferMemory",
+      "drawCall",
+      "triangles",
+      "webglContext"
+    ];
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
this.items = [];
this.items = ["fps", "memory", "drawCall", "triangles", "textures", "shaders", "size", "webglContext"];
this.items = ["fps", "memory", "totalGraphicsMemory", "textureMemory", "bufferMemory", "drawCall", "triangles", "webglContext"];
this.items = [
"fps",
"memory",
"totalGraphicsMemory",
"textureMemory",
"bufferMemory",
"drawCall",
"triangles",
"webglContext"
];
🧰 Tools
🪛 ESLint

[error] 69-69: Replace "fps",·"memory",·"totalGraphicsMemory",·"textureMemory",·"bufferMemory",·"drawCall",·"triangles",·"webglContext" with ⏎······"fps",⏎······"memory",⏎······"totalGraphicsMemory",⏎······"textureMemory",⏎······"bufferMemory",⏎······"drawCall",⏎······"triangles",⏎······"webglContext"⏎····

(prettier/prettier)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/stats/src/Monitor.ts` around lines 68 - 69, The array initialization
for Monitor.items is duplicated and formatted in a way that triggers prettier;
remove the redundant this.items = [] assignment and replace the single-line
array with a properly formatted array literal assigned to this.items (keep the
existing values "fps", "memory", "totalGraphicsMemory", "textureMemory",
"bufferMemory", "drawCall", "triangles", "webglContext") inside the Monitor
constructor or initializer so the assignment is singular and conforms to
prettier formatting for arrays.

Copy link
Collaborator

@cptbtptpbcptdtptp cptbtptpbcptdtptp left a comment

Choose a reason for hiding this comment

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

+1

@cptbtptpbcptdtptp cptbtptpbcptdtptp merged commit 96c66fb into galacean:dev/2.0 Mar 4, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Is there a way to get accurate or estimated VRAM usage?

2 participants