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
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-26 - Use Typed Arrays and For Loops for Metrics Calculation
**Learning:** Using `Map` caching and array methods like `reduce` and `forEach` introduces overhead from JS engine callback allocation, garbage collection, and hash-lookup, which can be significant in high-frequency functions like `computeTaskMetrics` that runs every render cycle.
**Action:** Replaced `Map` with typed arrays (`Int32Array`) and `reduce`/`forEach` with standard `for` loops for O(N) iteration in hot paths.
23 changes: 14 additions & 9 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 totalTasks = state.tasks.length;
// ⚡ Bolt: Replace Map with Int32Array and reduce/forEach with for loops for O(N) high-performance iteration
const durationCache = new Int32Array(totalTasks);

let totalDays = 0;
for (let i = 0; i < totalTasks; i++) {
const task = state.tasks[i];
const duration = calculateDurationDays(task.plannedStartDate, task.plannedEndDate);
durationCache.set(task.id, duration);
return sum + duration;
}, 0);
durationCache[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 < totalTasks; i++) {
const task = state.tasks[i];
const durationDays = durationCache[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;
Expand All @@ -1408,7 +1413,7 @@ function computeTaskMetrics() {
plannedDateWarning,
actualDateWarning
});
});
}
Comment on lines 1413 to +1416

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Info: Int32Array cache is behaviorally equivalent

Both loops iterate state.tasks in the same order over the unchanged array, so index alignment holds. calculateDurationDays returns non-negative integers within Int32 range given the 4-digit year cap, so no truncation. The index-based cache is more robust to duplicate task ids than the old id-keyed Map.

(Refers to this code)

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.


return {
totalDays,
Expand Down
Loading