Skip to content

Commit 1d8a17d

Browse files
authored
geometry: skip getFloatData if not needed (#17031)
The `setVerticesBuffer` method currently unconditionally calls `buffer.getFloatData` when setting a position buffer. However, if `useBoundingInfoFromGeometry` is true and `_boundingInfo` is already set (a common scenario for glTF models), the data returned by `getFloatData` is ignored within the `_updateExtend` method. This `getFloatData` operation is profiled to be CPU and RAM intensive, contributing significantly to model loading times and potentially causing major garbage collection events. This change optimizes performance by conditionally calling `buffer.getFloatData`. It now passes `null` to `_updateExtend` when `useBoundingInfoFromGeometry` is true and `_boundingInfo` exists, ensuring the expensive data retrieval is only performed when its result is actually needed and used. This will improve loading performance and reduce GC pressure, particularly for glTF assets. Forum post: <https://forum.babylonjs.com/t/redundant-getfloatdata-in-geometry-setverticesbuffer/60063>
1 parent 3336141 commit 1d8a17d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

packages/dev/core/src/Meshes/geometry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ export class Geometry implements IGetSetVerticesData {
310310
if (kind === VertexBuffer.PositionKind) {
311311
this._totalVertices = totalVertices ?? buffer._maxVerticesCount;
312312

313-
this._updateExtend(buffer.getFloatData(this._totalVertices));
313+
this._updateExtend(this.useBoundingInfoFromGeometry && this._boundingInfo ? null : buffer.getFloatData(this._totalVertices));
314314
this._resetPointsArrayCache();
315315

316316
// this._extend can be empty if buffer.getFloatData(this._totalVertices) returned null

0 commit comments

Comments
 (0)