Skip to content
Open
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
@@ -1,3 +1,7 @@
## 2026-11-01 - Replace Math.max with reduce
**Learning:** Using `Math.max(...array)` with the spread operator on potentially large arrays creates an O(N) intermediate memory allocation and risks 'Maximum call stack size exceeded' errors.
**Action:** Use a memory-efficient `Array.prototype.reduce()` pass for array maximum/minimum calculations instead.

## 2026-11-08 - Lift loop invariants in map
**Learning:** Identifying invariant calculations (e.g., `Math.max(values.length - 1, 1)`) inside `.map()` iterations or React render loops and lifting them outside the loop into a constant prevents redundant CPU overhead on every iteration.
**Action:** Lift invariant loop calculations into pre-computed constants whenever possible to reduce redundant execution overhead.
4 changes: 3 additions & 1 deletion apps/console/src/app/(console)/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ function TrendChart({

// ⚑ Bolt: Avoid O(N) intermediate array allocation and spread operator overhead by using a single reduce pass.
const max = values.reduce((m, v) => (v > m ? v : m), 1);
// ⚑ Bolt: Lift invariant calculation outside of map loop
const xDenominator = Math.max(values.length - 1, 1);
const linePoints = values
.map((value, index) => {
const x = (index / Math.max(values.length - 1, 1)) * 100;
const x = (index / xDenominator) * 100;
const y = 92 - (value / max) * 70;
return `${x},${y}`;
})
Expand Down
8 changes: 6 additions & 2 deletions apps/console/src/components/console/charts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ export function LinePulse({

// ⚑ Bolt: Avoid O(N) intermediate array allocation and spread operator overhead by using a single reduce pass.
const max = values.reduce((m, v) => (v > m ? v : m), 1);
// ⚑ Bolt: Lift invariant calculation outside of map loop
const xDenominator = Math.max(values.length - 1, 1);
const points = values
.map((value, index) => {
const x = (index / Math.max(values.length - 1, 1)) * 100;
const x = (index / xDenominator) * 100;
const y = 100 - (value / max) * 84;
return `${x},${y}`;
})
Expand Down Expand Up @@ -95,9 +97,11 @@ export function TrendAreaChart({

// ⚑ Bolt: Avoid O(N) intermediate array allocation and spread operator overhead by using a single reduce pass.
const max = values.reduce((m, v) => (v > m ? v : m), 1);
// ⚑ Bolt: Lift invariant calculation outside of map loop
const xDenominator = Math.max(values.length - 1, 1);
const linePoints = values
.map((value, index) => {
const x = (index / Math.max(values.length - 1, 1)) * 100;
const x = (index / xDenominator) * 100;
const y = 92 - (value / max) * 70;
return `${x},${y}`;
})
Expand Down
Loading