Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGPURenderer: Reduce memory churn when using chain maps. #30249

Merged
merged 1 commit into from
Jan 2, 2025

Conversation

Mugen87
Copy link
Collaborator

@Mugen87 Mugen87 commented Jan 2, 2025

Related issue: -

Description

While working at the docs, I've noticed WebGPURenderer allocates temporary array objects when using chain maps. Most of the methods using chain maps are executed at least once per frame. To keep the GC overhead to a minimum, we should avoid this kind of object creation whenever possible.

This PR ensures modules using a chain map manage their keys array in module scope. This pattern has already been adopted in RenderObjects and is now used globally. Besides, at the end of the chain map usage the array is truncated to a length of 0 otherwise it would keep references to objects like scenes or cameras. We do something similar in RenderList.finish() to ensure user created objects can actually GC collected. Setting the array length to 0 should still be the fastest way to clear an array in JavaScript.

Copy link

github-actions bot commented Jan 2, 2025

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 339.44
79.06
339.44
79.06
+0 B
+0 B
WebGPU 489.62
135.75
489.78
135.84
+165 B
+92 B
WebGPU Nodes 489.08
135.64
489.25
135.73
+165 B
+93 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 465.3
112.11
465.3
112.11
+0 B
+0 B
WebGPU 559.12
151.27
559.28
151.36
+165 B
+85 B
WebGPU Nodes 515.19
141.06
515.36
141.13
+165 B
+77 B

@sunag sunag added this to the r173 milestone Jan 2, 2025
@sunag sunag merged commit 00fa06f into mrdoob:dev Jan 2, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants