From fd327b731a9ce21154bb7a0385925977e8628d67 Mon Sep 17 00:00:00 2001 From: Blake Roberts Date: Thu, 28 Nov 2024 18:29:20 -0700 Subject: [PATCH] [#3284] perf: reduce allocations for GraphicsGroup draw calls (#3285) Closes #3284 ## Changes: - reuse single cumulative bounding box for local bounds calculation of `GraphicsGroup` to reduce per-draw allocations --- CHANGELOG.md | 1 + src/engine/Graphics/GraphicsGroup.ts | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a459901c7..e3e578b3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -238,6 +238,7 @@ are doing mtv adjustments during precollision. * `EventEmitter`s * `GraphicsSystem` entity iteration * `PointerSystem` entity iteration +- Perf improvements to `GraphicsGroup` by reducing per draw allocations in bounds calculations ### Changed diff --git a/src/engine/Graphics/GraphicsGroup.ts b/src/engine/Graphics/GraphicsGroup.ts index bc44b119e..430afa8a9 100644 --- a/src/engine/Graphics/GraphicsGroup.ts +++ b/src/engine/Graphics/GraphicsGroup.ts @@ -58,16 +58,16 @@ export class GraphicsGroup extends Graphic implements HasTick { } public get localBounds(): BoundingBox { - let bb = new BoundingBox(); + const bb = new BoundingBox(); for (const member of this.members) { if (member instanceof Graphic) { - bb = member.localBounds.combine(bb); + member.localBounds.combine(bb, bb); } else { const { graphic, offset: pos, useBounds } = member; const shouldUseBounds = useBounds === undefined ? true : useBounds; if (graphic) { if (shouldUseBounds) { - bb = graphic.localBounds.translate(pos).combine(bb); + graphic.localBounds.translate(pos).combine(bb, bb); } } else { this._logger.warnOnce(`Graphics group member has an null or undefined graphic, member definition: ${JSON.stringify(member)}.`);