From b77ce2154df6d76fb4f40f7fe4b9a33fe1b9fdb2 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Sun, 2 Aug 2026 14:09:38 +0000 Subject: [PATCH] =?UTF-8?q?=EC=84=B1=EB=8A=A5=20=EA=B0=9C=EC=84=A0:=20?= =?UTF-8?q?=EB=8C=80=EC=9A=A9=EB=9F=89=20=EB=B0=94=EC=9D=B4=ED=8A=B8=20?= =?UTF-8?q?=EB=B0=B0=EC=97=B4=20=EA=B2=80=EC=A6=9D=20=EC=8B=9C=20.every()?= =?UTF-8?q?=EB=A5=BC=20for=20=EB=A3=A8=ED=94=84=EB=A1=9C=20=EA=B5=90?= =?UTF-8?q?=EC=B2=B4=ED=95=98=EC=97=AC=20O(1)=20=EB=A9=94=EB=AA=A8?= =?UTF-8?q?=EB=A6=AC=20=EC=B5=9C=EC=A0=81=ED=99=94=20=EC=88=98=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .jules/bolt.md | 1 + apps/desktop/src/features/score/scoreStorage.ts | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.jules/bolt.md b/.jules/bolt.md index d54cf10fc..2c0d1c4f0 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -61,3 +61,4 @@ ## 2026-07-13 - Array.from mapping optimization **Learning:** Using `Array.from({ length: N }).map(...)` creates an intermediate array of `undefined` values which requires memory allocation and garbage collection, adding O(N) unnecessary overhead in frequently re-rendered UI components. **Action:** Use `Array.from({ length: N }, (_, index) => ...)` to map elements directly during array creation, avoiding intermediate allocations. +## 2026-08-02 - O(1) Memory Array Validation\n**Learning:** Using `Array.every()` on large byte arrays in `scoreStorage.ts` allocates unnecessary intermediate callbacks (O(N) overhead) causing garbage collection spikes.\n**Action:** Replaced `.every()` with a standard `for` loop that avoids callback overhead and exits early upon encountering a non-number.\n diff --git a/apps/desktop/src/features/score/scoreStorage.ts b/apps/desktop/src/features/score/scoreStorage.ts index 492f12591..88a1706dd 100644 --- a/apps/desktop/src/features/score/scoreStorage.ts +++ b/apps/desktop/src/features/score/scoreStorage.ts @@ -91,8 +91,19 @@ export async function readScorePdf(projectId: string, scoreId: string): Promise< if (response instanceof ArrayBuffer) { return new Uint8Array(response); } - if (Array.isArray(response) && response.every((byte) => typeof byte === "number")) { - return Uint8Array.from(response as number[]); + if (Array.isArray(response)) { + // Performance: Avoid .every() on large byte arrays as it creates O(N) intermediate callback allocations. + // Use a standard for loop with an early return to achieve O(1) memory and significantly faster execution. + let isNumberArray = true; + for (let i = 0; i < response.length; i++) { + if (typeof response[i] !== "number") { + isNumberArray = false; + break; + } + } + if (isNumberArray) { + return Uint8Array.from(response as number[]); + } } throw new Error(INVALID_RESPONSE_MESSAGE);