From 7bf7494484b8b01070d6febace34f2b3798cda7f Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Thu, 6 Aug 2026 13:49:45 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9A=A1=20Bolt:=20[=EC=84=B1=EB=8A=A5=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0]=20O(N)=20=EC=BD=9C=EB=B0=B1=20=ED=95=A0?= =?UTF-8?q?=EB=8B=B9=20=EC=98=A4=EB=B2=84=ED=97=A4=EB=93=9C=20=EA=B0=90?= =?UTF-8?q?=EC=86=8C=EB=A5=BC=20=EC=9C=84=ED=95=9C=20for=20=EB=A3=A8?= =?UTF-8?q?=ED=94=84=20=EC=B5=9C=EC=A0=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .jules/bolt.md | 4 ++++ .../src/features/score/scoreStorage.test.ts | 16 ++++++++++++++++ apps/desktop/src/features/score/scoreStorage.ts | 13 +++++++++++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/.jules/bolt.md b/.jules/bolt.md index d54cf10fc..745521893 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -61,3 +61,7 @@ ## 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-06 - [Array density check optimization in scoreStorage] +**Learning:** Using Array.every() to validate byte arrays creates O(N) callback invocation overhead and unnecessary intermediate allocations. +**Action:** Replaced response.every(...) with a standard for loop and early break to achieve O(1) memory and significantly faster execution for large arrays. diff --git a/apps/desktop/src/features/score/scoreStorage.test.ts b/apps/desktop/src/features/score/scoreStorage.test.ts index 0feec199e..6b848f9ba 100644 --- a/apps/desktop/src/features/score/scoreStorage.test.ts +++ b/apps/desktop/src/features/score/scoreStorage.test.ts @@ -32,4 +32,20 @@ describe("scoreStorage bridge resolution", () => { BRIDGE_UNAVAILABLE_MESSAGE ); }); + + it("handles valid number array response in readScorePdf", async () => { + const tauriWindow = window as TauriWindow; + tauriWindow.__TAURI_INVOKE__ = vi.fn().mockResolvedValue([1, 2, 3]); + const result = await readScorePdf("project-1", "score-1"); + expect(result).toBeInstanceOf(Uint8Array); + expect(result.length).toBe(3); + }); + + it("triggers early exit for mixed arrays in readScorePdf", async () => { + const tauriWindow = window as TauriWindow; + tauriWindow.__TAURI_INVOKE__ = vi.fn().mockResolvedValue([1, "two", 3]); + await expect(readScorePdf("project-1", "score-1")).rejects.toThrow( + "Invalid score bridge response" + ); + }); }); diff --git a/apps/desktop/src/features/score/scoreStorage.ts b/apps/desktop/src/features/score/scoreStorage.ts index 492f12591..b3ce9c6f4 100644 --- a/apps/desktop/src/features/score/scoreStorage.ts +++ b/apps/desktop/src/features/score/scoreStorage.ts @@ -91,8 +91,17 @@ 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)) { + let isNumericArray = true; + for (let i = 0; i < response.length; i++) { + if (typeof response[i] !== "number") { + isNumericArray = false; + break; + } + } + if (isNumericArray) { + return Uint8Array.from(response as number[]); + } } throw new Error(INVALID_RESPONSE_MESSAGE); From b138ca9b4d6ab087580d626e018274b5fe7d595b Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Thu, 6 Aug 2026 13:54:51 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9A=A1=20Bolt:=20[=EC=84=B1=EB=8A=A5=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0]=20O(N)=20=EC=BD=9C=EB=B0=B1=20=ED=95=A0?= =?UTF-8?q?=EB=8B=B9=20=EC=98=A4=EB=B2=84=ED=97=A4=EB=93=9C=20=EA=B0=90?= =?UTF-8?q?=EC=86=8C=EB=A5=BC=20=EC=9C=84=ED=95=9C=20for=20=EB=A3=A8?= =?UTF-8?q?=ED=94=84=20=EC=B5=9C=EC=A0=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 32 +++----------------------------- 1 file changed, 3 insertions(+), 29 deletions(-) diff --git a/package-lock.json b/package-lock.json index cf1c991c1..ff7604e43 100644 --- a/package-lock.json +++ b/package-lock.json @@ -955,7 +955,6 @@ "os": [ "aix" ], - "peer": true, "engines": { "node": ">=18" } @@ -973,7 +972,6 @@ "os": [ "android" ], - "peer": true, "engines": { "node": ">=18" } @@ -991,7 +989,6 @@ "os": [ "android" ], - "peer": true, "engines": { "node": ">=18" } @@ -1009,7 +1006,6 @@ "os": [ "android" ], - "peer": true, "engines": { "node": ">=18" } @@ -1027,7 +1023,6 @@ "os": [ "darwin" ], - "peer": true, "engines": { "node": ">=18" } @@ -1045,7 +1040,6 @@ "os": [ "darwin" ], - "peer": true, "engines": { "node": ">=18" } @@ -1063,7 +1057,6 @@ "os": [ "freebsd" ], - "peer": true, "engines": { "node": ">=18" } @@ -1081,7 +1074,6 @@ "os": [ "freebsd" ], - "peer": true, "engines": { "node": ">=18" } @@ -1099,7 +1091,6 @@ "os": [ "linux" ], - "peer": true, "engines": { "node": ">=18" } @@ -1117,7 +1108,6 @@ "os": [ "linux" ], - "peer": true, "engines": { "node": ">=18" } @@ -1135,7 +1125,6 @@ "os": [ "linux" ], - "peer": true, "engines": { "node": ">=18" } @@ -1153,7 +1142,6 @@ "os": [ "linux" ], - "peer": true, "engines": { "node": ">=18" } @@ -1171,7 +1159,6 @@ "os": [ "linux" ], - "peer": true, "engines": { "node": ">=18" } @@ -1189,7 +1176,6 @@ "os": [ "linux" ], - "peer": true, "engines": { "node": ">=18" } @@ -1207,7 +1193,6 @@ "os": [ "linux" ], - "peer": true, "engines": { "node": ">=18" } @@ -1225,7 +1210,6 @@ "os": [ "linux" ], - "peer": true, "engines": { "node": ">=18" } @@ -1243,7 +1227,6 @@ "os": [ "linux" ], - "peer": true, "engines": { "node": ">=18" } @@ -1261,7 +1244,6 @@ "os": [ "netbsd" ], - "peer": true, "engines": { "node": ">=18" } @@ -1279,7 +1261,6 @@ "os": [ "netbsd" ], - "peer": true, "engines": { "node": ">=18" } @@ -1297,7 +1278,6 @@ "os": [ "openbsd" ], - "peer": true, "engines": { "node": ">=18" } @@ -1315,7 +1295,6 @@ "os": [ "openbsd" ], - "peer": true, "engines": { "node": ">=18" } @@ -1333,7 +1312,6 @@ "os": [ "openharmony" ], - "peer": true, "engines": { "node": ">=18" } @@ -1351,7 +1329,6 @@ "os": [ "sunos" ], - "peer": true, "engines": { "node": ">=18" } @@ -1369,7 +1346,6 @@ "os": [ "win32" ], - "peer": true, "engines": { "node": ">=18" } @@ -1387,7 +1363,6 @@ "os": [ "win32" ], - "peer": true, "engines": { "node": ">=18" } @@ -1405,7 +1380,6 @@ "os": [ "win32" ], - "peer": true, "engines": { "node": ">=18" } @@ -7179,9 +7153,9 @@ } }, "node_modules/undici": { - "version": "7.28.0", - "resolved": "https://registry.npmjs.org/undici/-/undici-7.28.0.tgz", - "integrity": "sha512-cRZYrTDwWznlnRiPjggAGxZXanty6M8RV1ff8Wm4LWXBp7/IG8v5DnOm74DtUBp9OONpK75YlPnIjQqX0dBDtA==", + "version": "7.29.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-7.29.0.tgz", + "integrity": "sha512-IDxfleLmmbSskfWSUATiN1nfn2rDuvnMOqb5CWR92iIfojA0Ud+ulOAAEQ57LPr9rWmsreUyf5lwyao+7GNNVw==", "dev": true, "license": "MIT", "engines": {