diff --git a/.jules/bolt.md b/.jules/bolt.md index f1a8c1466..8186a520f 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -77,3 +77,7 @@ 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-08-17 - Optimize Array.from for GC Overhead in sanitizeHandleId +**Learning:** Using `Array.from(string)` to iterate over strings creates intermediate array allocations, increasing garbage collection overhead. In hot paths like frontend ERD graph processing (`sanitizeHandleId` in `handleUtils.ts`), removing these allocations provides a measurable performance improvement. +**Action:** Replace `Array.from()` with an iterative `for...of` loop in high-frequency string processing functions to avoid intermediate array instantiation and reduce GC pressure. diff --git a/frontend/src/erd/handleUtils.ts b/frontend/src/erd/handleUtils.ts index 054d5ab2a..5b5f2cf30 100644 --- a/frontend/src/erd/handleUtils.ts +++ b/frontend/src/erd/handleUtils.ts @@ -1,16 +1,23 @@ export function sanitizeHandleId(columnName: string): string { - const encoded = Array.from(columnName, (char) => { - // Array.from only yields non-empty Unicode scalars, so codePointAt(0) is defined. - return char.codePointAt(0)!.toString(16).padStart(4, '0') - }).join('-') + if (!columnName) return 'c-empty'; - return `c-${encoded || 'empty'}` + let encoded = ''; + let isFirst = true; + for (const char of columnName) { + if (!isFirst) { + encoded += '-'; + } + encoded += char.codePointAt(0)!.toString(16).padStart(4, '0'); + isFirst = false; + } + + return `c-${encoded}`; } export function sourceColumnHandleId(columnName: string): string { - return `src-${sanitizeHandleId(columnName)}` + return `src-${sanitizeHandleId(columnName)}`; } export function targetColumnHandleId(columnName: string): string { - return `tgt-${sanitizeHandleId(columnName)}` + return `tgt-${sanitizeHandleId(columnName)}`; }