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
4 changes: 4 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
## 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-10 - JSDOM Global Caching Danger
**Learning:** Caching unattached DOM elements in module-level global variables (e.g., `let rowTemplate = document.createElement('tr')`) and reusing them via `cloneNode()` across renders is a dangerous anti-pattern in environments tested with JSDOM. JSDOM recreates the `document` context per test. Cloned nodes retain the original `document` reference, causing `HierarchyRequestError` or `WrongDocumentError` when appending them to a new test's `document`.
**Action:** Avoid global DOM caching optimizations in frontend codebases heavily reliant on JSDOM. If caching is necessary for extreme performance, encapsulate the template cache within a factory function or class that is scoped to the current `document` instance, or ensure templates are re-initialized when the `document` context changes.
34 changes: 18 additions & 16 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1370,21 +1370,28 @@ 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 baseDate = state.baseDate;
const taskCount = state.tasks.length;

// ⚡ Bolt: Use Int32Array and standard loops to eliminate JS engine allocation overhead
// from Map lookups and Array callback methods (reduce/forEach) during O(N) calculations.
const durations = new Int32Array(taskCount);
let totalDays = 0;

for (let i = 0; i < taskCount; i++) {
const task = state.tasks[i];
const duration = calculateDurationDays(task.plannedStartDate, task.plannedEndDate);
durationCache.set(task.id, duration);
return sum + duration;
}, 0);
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 < taskCount; i++) {
const task = state.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;
Expand All @@ -1408,14 +1415,9 @@ function computeTaskMetrics() {
plannedDateWarning,
actualDateWarning
});
});
}

return {
totalDays,
totalWeightedPlannedRatio,
totalWeightedActualRatio,
byTask
};
return { totalDays, totalWeightedPlannedRatio, totalWeightedActualRatio, byTask };
}

const PROGRESS_STATE_EMPTY = Object.freeze({ label: '', className: '', description: '' });
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"dependencies": {
"@hono/node-server": "^2.0.12",
"hono": "^4.13.1"
"hono": "^4.12.32"
},
"devDependencies": {
"@playwright/test": "1.61.1",
Expand Down
Loading