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-07-17 - Optimize Gantt Chart Rendering
**Learning:** O(N) loops creating multiple DOM nodes via document.createElement causes significant JS-to-C++ allocation overhead.
**Action:** When creating thousands of elements like in gantt chart cells or rows, cache static templates utilizing cloneNode() instead of dynamically creating elements.
31 changes: 26 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2315,6 +2315,11 @@ function renderGantt() {
elements.ganttContent.replaceChildren(shell);
}

// ⚡ Bolt: Cache template elements for Gantt rendering loops
let ganttRowTemplate = null;
let ganttChartCellTemplate = null;
let ganttChartTrackTemplate = null;

function createGanttMetaTable() {
const table = document.createElement('table');
const thead = document.createElement('thead');
Expand All @@ -2340,8 +2345,13 @@ function createGanttMetaTable() {
thead.appendChild(headerRow);

const tbody = document.createElement('tbody');

if (!ganttRowTemplate) {
ganttRowTemplate = document.createElement('tr');
}

state.tasks.forEach((task) => {
const row = document.createElement('tr');
const row = ganttRowTemplate.cloneNode(false);
row.append(
createTableCell('', createTreeCellContent(task.phase || task.activity || task.task || '-', task.depth)),
createTableCell('', createTextCellContent(task.activity)),
Expand Down Expand Up @@ -2385,13 +2395,24 @@ function createGanttChartTable(weeks, weekdays, totalWidth) {
thead.append(weekRow, dayRow);

const tbody = document.createElement('tbody');

if (!ganttRowTemplate) {
ganttRowTemplate = document.createElement('tr');
}
if (!ganttChartCellTemplate) {
ganttChartCellTemplate = document.createElement('td');
}
if (!ganttChartTrackTemplate) {
ganttChartTrackTemplate = document.createElement('div');
ganttChartTrackTemplate.className = 'gantt-day-track';
}

state.tasks.forEach((task) => {
const row = document.createElement('tr');
const cell = document.createElement('td');
const row = ganttRowTemplate.cloneNode(false);
const cell = ganttChartCellTemplate.cloneNode(false);
cell.colSpan = weekdays.length;

const track = document.createElement('div');
track.className = 'gantt-day-track';
const track = ganttChartTrackTemplate.cloneNode(false);
track.style.width = `${totalWidth}px`;

const planBar = createGanttBarElement(task.plannedStartDate, task.plannedEndDate, weekdays, 'plan', task);
Expand Down
Loading