From 47e9a00715474ef047a827a49a32d60657a7270f Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Tue, 21 Jul 2026 13:55:03 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20[performance=20improvement]?= =?UTF-8?q?=20Remove=20intermediate=20array=20allocation=20in=20uniqueBusi?= =?UTF-8?q?nessGroupId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .jules/bolt.md | 3 +++ frontend/src/erd/businessGroups.ts | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) 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}`)) {