Skip to content

Commit d050d8e

Browse files
WebGPURenderer: Trim compute-path allocations.
- Renderer.compute: cache a singleton array for single-node dispatches instead of allocating [ computeNode ] per call. - WebGPUTimestampQueryPool._resolveQueries: reuse scratch submit array. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent d0308b4 commit d050d8e

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

src/renderers/common/Renderer.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2755,7 +2755,19 @@ class Renderer {
27552755
const bindings = this._bindings;
27562756
const nodes = this._nodes;
27572757

2758-
const computeList = Array.isArray( computeNodes ) ? computeNodes : [ computeNodes ];
2758+
let computeList;
2759+
2760+
if ( Array.isArray( computeNodes ) ) {
2761+
2762+
computeList = computeNodes;
2763+
2764+
} else {
2765+
2766+
if ( this._computeSingleton === undefined ) this._computeSingleton = [ null ];
2767+
this._computeSingleton[ 0 ] = computeNodes;
2768+
computeList = this._computeSingleton;
2769+
2770+
}
27592771

27602772
if ( computeList[ 0 ] === undefined || computeList[ 0 ].isComputeNode !== true ) {
27612773

src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { error, warnOnce } from '../../../utils.js';
22
import TimestampQueryPool from '../../common/TimestampQueryPool.js';
33

4+
const _submitArray = [ null ];
5+
46
/**
57
* Manages a pool of WebGPU timestamp queries for performance measurement.
68
* Extends the base TimestampQueryPool to provide WebGPU-specific implementation.
@@ -154,8 +156,9 @@ class WebGPUTimestampQueryPool extends TimestampQueryPool {
154156
bytesUsed
155157
);
156158

157-
const commandBuffer = commandEncoder.finish();
158-
this.device.queue.submit( [ commandBuffer ] );
159+
_submitArray[ 0 ] = commandEncoder.finish();
160+
this.device.queue.submit( _submitArray );
161+
_submitArray[ 0 ] = null;
159162

160163
if ( this.resultBuffer.mapState !== 'unmapped' ) {
161164

0 commit comments

Comments
 (0)