From 7a601f5374b6d573634f781d3f18a07d7852a1a7 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Fri, 7 Nov 2025 21:58:27 +0100 Subject: [PATCH] Fix CostMatrix.clone causing unnecessary memory pressure Since we're about to replace the whole of `_bits` with a new value, calling the constructor leads to the code creating a full 2500 big `UInt8Array` just to replace it instantly. Fix the issue by doing the same trick `CostMatrix.deserialize` does; use `Object.create` to skip the constructor cost. --- src/game/path-finder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/path-finder.js b/src/game/path-finder.js index b0eee069..52f432eb 100644 --- a/src/game/path-finder.js +++ b/src/game/path-finder.js @@ -32,7 +32,7 @@ exports.make = function(runtimeData, intents, register, globals) { }); CostMatrix.prototype.clone = register.wrapFn(function() { - var newMatrix = new CostMatrix; + const newMatrix = Object.create(CostMatrix.prototype); newMatrix._bits = new Uint8Array(this._bits); return newMatrix; });