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
1 change: 1 addition & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-11-23 - Avoid .every() for large array validation\n**Learning:** Using `Array.prototype.every()` for validating large byte arrays allocates an intermediate callback function repeatedly in a hot path, causing O(N) allocation overhead.\n**Action:** Use a standard `for` loop with an early `break` to keep memory usage at O(1) and improve execution speed.
9 changes: 9 additions & 0 deletions apps/desktop/src/features/score/scoreStorage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ describe("scoreStorage bridge resolution", () => {
delete tauriWindow.__TAURI_INVOKE__;
});

it("fails closed when readScorePdf receives an invalid array (early exit for non-number)", async () => {
const tauriWindow = window as TauriWindow;
tauriWindow.__TAURI_INVOKE__ = vi.fn().mockResolvedValue([1, 2, "not-a-number", 4]);

await expect(readScorePdf("project-1", "score-1")).rejects.toThrow(
"Invalid score bridge response"
);
});

it("fails closed on every command when there is no window (non-browser runtime)", async () => {
// Simulate a runtime without a DOM window (e.g. SSR / bundler prerender):
// getInvoke() must take the `typeof window === "undefined"` branch and
Expand Down
14 changes: 12 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,18 @@ 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 O(N) callback invocation overhead from .every()
let isDense = true;
for (let i = 0; i < response.length; i++) {
if (typeof response[i] !== "number") {
isDense = false;
break;
}
}
if (isDense) {
return Uint8Array.from(response as number[]);
}
}

throw new Error(INVALID_RESPONSE_MESSAGE);
Expand Down
32 changes: 3 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading