diff --git a/.jules/bolt.md b/.jules/bolt.md index 38d4b732..83323e63 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -41,3 +41,6 @@ ## 2025-02-15 - Replace Array.from(map.values()).map with a for...of loop **Learning:** Using `Array.from(map.values()).map(...)` creates an unnecessary intermediate array which wastes memory allocation and garbage collection time, particularly for frequently re-rendered components handling large collections. **Action:** Use a `for...of` loop over `map.values()` to iterate and push mapped elements directly into the final array for O(1) memory and avoiding intermediate array allocations. +## 2024-07-03 - Hoisting Static React Math Structures +**Learning:** React render functions can contain mathematically generated static structures, such as decorative lists created with `Array.from().map()`. While small, leaving these inline allocates new arrays and objects on every render cycle, increasing garbage collection pressure. This is a common performance pitfall for purely decorative UI elements. +**Action:** When finding static structural elements generated by arrays, hoist them entirely out of the component as module-level constants to ensure React reuses the exact same reference, bypassing DOM diffing allocation overhead. diff --git a/apps/desktop/src/App.tsx b/apps/desktop/src/App.tsx index 24f5fb09..2b4422f8 100644 --- a/apps/desktop/src/App.tsx +++ b/apps/desktop/src/App.tsx @@ -42,6 +42,19 @@ import { } from "./lib/analysis"; import { createTranslator, detectPreferredLocale } from "./i18n"; import { Workspace } from "./features/workspace/Workspace"; + +// Performance Optimization: Extract static decorative elements outside of the component. +// Creating these 34 spans inside the render function via `Array.from().map()` causes +// unnecessary object allocation and garbage collection overhead on every re-render. +// By hoisting it to a module-level constant, we reuse the exact same React elements +// for a small but measurable reduction in render cycle latency. +const LOCAL_FIRST_WAVEFORM_BARS = Array.from({ length: 34 }).map((_, index) => ( + +)); import { EmptyState, ErrorState, LoadingState } from "./features/workspace/WorkspaceStates"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; @@ -523,13 +536,7 @@ export function App() {