From 8cf9114b9dcc85bd99e81f2ca2771fe74f958292 Mon Sep 17 00:00:00 2001 From: Michael Green <84688932+michael-j-green@users.noreply.github.com> Date: Sat, 17 Jan 2026 18:01:44 +1100 Subject: [PATCH] Optimize data concatenation in EJS_Download by using Blob to reduce iterations --- data/src/cache.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/data/src/cache.js b/data/src/cache.js index b3230c3..9e6cbd2 100644 --- a/data/src/cache.js +++ b/data/src/cache.js @@ -133,12 +133,10 @@ class EJS_Download { onProgress("downloading", Math.floor(received / contentLength * 100), received, contentLength); } } - data = new Uint8Array(chunks.reduce((acc, val) => acc + val.length, 0)); - let offset = 0; - for (const chunk of chunks) { - data.set(chunk, offset); - offset += chunk.length; - } + // Optimize concatenation by leveraging Blob to avoid double iteration + const blob = new Blob(chunks); + const ab = await blob.arrayBuffer(); + data = new Uint8Array(ab); } else { data = await resp[responseType](); }