diff --git a/.jules/bolt.md b/.jules/bolt.md index f1a8c146..d66e480e 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -77,3 +77,6 @@ Optimized metric route processing to O(N) by creating a mapping of routes direct ## 2024-07-13 - [Optimize Export Dictionary FK lookups] **Learning:** Found O(N * C * E) performance bottleneck in ERD export dictionaries due to repeated array searching with `edges.some()` inside a nested loop over nodes and columns. **Action:** Replace repeated linear array scans for edges by precomputing O(1) Set lookups of foreign key column handles per node before looping. +## 2024-05-14 - Map/Set construction array allocation overhead +**Learning:** Initializing Maps or Sets using `new Set(array.map(...))` creates unnecessary intermediate arrays and puts pressure on the garbage collector. In highly interactive applications (like this React ERD), frequent GC pauses cause jank. +**Action:** Populate Maps and Sets iteratively using `for...of` loops, avoiding `.map()` when building lookup structures. diff --git a/frontend/src/erd/businessGroups.ts b/frontend/src/erd/businessGroups.ts index f60edd24..838b50c2 100644 --- a/frontend/src/erd/businessGroups.ts +++ b/frontend/src/erd/businessGroups.ts @@ -41,7 +41,11 @@ export function uniqueBusinessGroupId( existingGroups: BusinessGroup[], ): string { const baseId = buildBusinessGroupId(name); - const existingIds = new Set(existingGroups.map((group) => group.id)); + // ⚡ Bolt: Populate Set iteratively to avoid array allocation overhead (O(N)) from .map() + const existingIds = new Set(); + for (const group of existingGroups) { + existingIds.add(group.id); + } if (!existingIds.has(baseId)) return baseId; let suffix = 2; while (existingIds.has(`${baseId}_${suffix}`)) {