Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,8 @@
## 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-07-20 - Avoid Array.every() for large byte array validation

**Learning:** Validating large payloads over the IPC bridge with `.every()` creates significant O(N) intermediate callback allocations and Garbage Collection overhead on the critical path.
**Action:** Replace `.every()` with a standard `for...of` loop with an early `break` for O(1) memory and substantially faster checks for malformed payload chunks.
14 changes: 14 additions & 0 deletions apps/desktop/src/features/score/scoreStorage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,18 @@ describe("scoreStorage bridge resolution", () => {
BRIDGE_UNAVAILABLE_MESSAGE
);
});

it("fails when the response array contains non-number elements", async () => {
const tauriWindow = window as TauriWindow;
tauriWindow.__TAURI_INVOKE__ = async (command: string) => {
if (command === "read_score_pdf") {
return [1, 2, "not a number", 4];
}
return null;
};

await expect(readScorePdf("project-1", "score-1")).rejects.toThrow(
"Invalid score bridge response"
);
});
});
13 changes: 11 additions & 2 deletions apps/desktop/src/features/score/scoreStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 isValid = true;
for (const byte of response) {
if (typeof byte !== "number") {
isValid = false;
break;
}
}
if (isValid) {
return Uint8Array.from(response as number[]);
}
}

throw new Error(INVALID_RESPONSE_MESSAGE);
Expand Down
Loading