From 31c20c7e6037975ac8e354d50a49a6adfa0dca72 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Sun, 16 Aug 2026 14:22:36 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20computeTaskMetrics=20?= =?UTF-8?q?=EC=84=B1=EB=8A=A5=20=EC=B5=9C=EC=A0=81=ED=99=94=20(O(N)=20?= =?UTF-8?q?=EB=A3=A8=ED=94=84=20=EA=B0=9C=EC=84=A0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit app.js의 computeTaskMetrics 내에서 reduce, forEach와 Map 객체를 사용하던 부분을 기본 for 루프와 Int32Array로 변경하여 반복 콜백 할당, GC 및 해시 맵 조회 오버헤드를 제거했습니다. --- .jules/bolt.md | 3 +++ app.js | 25 +++++++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/.jules/bolt.md b/.jules/bolt.md index b08b203a..dc5437ea 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -4,3 +4,6 @@ ## 2026-07-12 - Optimize renderTaskRow DOM allocations **Learning:** Caching unattached template nodes and instantiating them via `.cloneNode(false)` reduces DOM instantiation overhead in O(N) render loops significantly. **Action:** Apply this optimization to other hot-path rendering elements such as rows, cells, and stack containers. +## 2026-08-16 - Use Int32Array and standard loops instead of Map and array methods +**Learning:** In hot loops, allocating callbacks for reduce/forEach and using Map incurs overhead due to GC and hash-lookup. +**Action:** Use Int32Array caching and standard for loops for measurable optimizations. diff --git a/app.js b/app.js index a04aae71..1d20a282 100644 --- a/app.js +++ b/app.js @@ -1370,21 +1370,26 @@ function validateDateRange(startLabel, startValue, endLabel, endValue, errors) { } function computeTaskMetrics() { - // ⚡ Bolt: Cache durationDays during total calculation to avoid recalculating for every task - const durationCache = new Map(); - const totalDays = state.tasks.reduce((sum, task) => { - const duration = calculateDurationDays(task.plannedStartDate, task.plannedEndDate); - durationCache.set(task.id, duration); - return sum + duration; - }, 0); + const tasks = state.tasks; + const numTasks = tasks.length; + // ⚡ Bolt: Use standard for-loop and Int32Array to eliminate callback allocation and Map overhead in O(N) loop + const durations = new Int32Array(numTasks); + let totalDays = 0; + + for (let i = 0; i < numTasks; i++) { + const duration = calculateDurationDays(tasks[i].plannedStartDate, tasks[i].plannedEndDate); + durations[i] = duration; + totalDays += duration; + } const baseDate = state.baseDate; const byTask = new Map(); let totalWeightedPlannedRatio = 0; let totalWeightedActualRatio = 0; - state.tasks.forEach((task) => { - const durationDays = durationCache.get(task.id); + for (let i = 0; i < numTasks; i++) { + const task = tasks[i]; + const durationDays = durations[i]; const weightRatio = totalDays > 0 ? durationDays / totalDays : 0; const plannedProgressRatio = calculatePlannedProgressRatio(baseDate, task.plannedStartDate, task.plannedEndDate, durationDays); const actualProgressRatio = (ACTUAL_PROGRESS_MAP[task.actualProgressStatus] || 0) / 100; @@ -1408,7 +1413,7 @@ function computeTaskMetrics() { plannedDateWarning, actualDateWarning }); - }); + } return { totalDays,