From 1e196270a0388cc204c1f64af05831220f8fe534 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Fri, 17 Jul 2026 04:01:35 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20=EB=8C=80=EA=B7=9C=EB=AA=A8?= =?UTF-8?q?=20=EB=B0=B0=EC=97=B4=EC=97=90=EC=84=9C=20`Math.max`=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=ED=98=B8=EC=B6=9C=20=EC=98=A4=EB=B2=84?= =?UTF-8?q?=ED=97=A4=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `apps/desktop/src/features/workspace/GrooveMap.tsx`에서 `renderedNotes.reduce`와 `Math.max`를 사용하는 부분을 표준 `for` 루프로 교체했습니다. 이 최적화는 큰 배열(예: 많은 전사 노트)을 처리할 때 반복마다 발생하는 클로저 할당과 함수 호출 오버헤드를 줄여 실행 속도를 높입니다. --- .jules/bolt.md | 4 ++++ apps/desktop/src/features/workspace/GrooveMap.tsx | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.jules/bolt.md b/.jules/bolt.md index d54cf10f..c9e5b63e 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-07-14 - O(N) iteration with reduced function overhead for finding maximum values +**Learning:** Using `Array.prototype.reduce()` coupled with `Math.max()` to find the maximum value in a large array (like transcription notes) introduces significant function call overhead, allocating intermediate closures for each item. +**Action:** Prefer standard `for` loops with simple reassignment over `.reduce()` for finding extreme values in performance-critical paths, especially for arrays that can grow very large. diff --git a/apps/desktop/src/features/workspace/GrooveMap.tsx b/apps/desktop/src/features/workspace/GrooveMap.tsx index 2745d4d7..2defcdd0 100644 --- a/apps/desktop/src/features/workspace/GrooveMap.tsx +++ b/apps/desktop/src/features/workspace/GrooveMap.tsx @@ -17,7 +17,14 @@ function GrooveMapComponent({ notes, isLoading }: GrooveMapProps) { // Find max offset to determine timeline width const maxTime = useMemo(() => { - return renderedNotes.reduce((max, n) => Math.max(max, n.offset), 10); + // Performance: Avoid function call overhead of .reduce() and Math.max for large arrays + let max = 10; + for (let i = 0; i < renderedNotes.length; i++) { + if (renderedNotes[i].offset > max) { + max = renderedNotes[i].offset; + } + } + return max; }, [renderedNotes]); // Unique pitches to determine vertical lanes (avoiding 88-key piano roll)