diff --git a/.jules/bolt.md b/.jules/bolt.md index b45f9caa..4e78cb39 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -60,3 +60,6 @@ Optimized metric route processing to O(N) by creating a mapping of routes direct ## 2026-06-25 - Avoid Map allocations in frontend ERD loops and mutate asyncpg records in-place **Learning:** The frontend `snapshotToGraph` iterates over thousands of columns to generate the graph, so repeated lookups and redundant collection assignments increase GC pressure. Backend snapshot column dictionaries are freshly instantiated for the payload, so `add_column_examples` can safely fill missing fields in place. **Action:** Reuse existing collections while aggregating relational data, create `Map`/`Set` entries only on first use, and check for missing example fields before calling expensive inference helpers. +## 2024-07-26 - Prevent memory churn in high-frequency React Flow filtering +**Learning:** In `frontend/src/App.tsx`, building search indexes on-the-fly during render using array manipulation methods like `.flatMap(...)` and spread syntax created massive intermediate memory allocation and severe garbage collection pressure when dealing with large ERD graphs (hundreds of nodes/columns). +**Action:** When filtering across large, complex graph state objects during render cycles or high-frequency callbacks (like keystrokes), use primitive string concatenation within loops instead of mapping to temporary arrays to minimize GC pauses and maintain smooth 60fps rendering. diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index e99700c5..86749c14 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -182,17 +182,14 @@ export default function App() { if (!normalizedNodeSearch) return new Set(); const matches = new Set(); for (const node of nodes) { - const haystack = [ - node.data.title, - node.data.comment ?? "", - ...node.data.columns.flatMap((column) => [ - column.column_name, - column.data_type, - column.column_comment ?? "", - ]), - ] - .join(" ") - .toLocaleLowerCase(); + // ⚡ Bolt: Replaced flatMap and join with direct string concatenation. + // This prevents intermediate array allocation, significantly reducing memory allocation + // and GC pressure during high-frequency search updates across large ERD graphs. + let haystack = (node.data.title + " " + (node.data.comment ?? "")).toLocaleLowerCase(); + for (const column of node.data.columns) { + haystack += " " + column.column_name.toLocaleLowerCase() + " " + column.data_type.toLocaleLowerCase() + " " + (column.column_comment ?? "").toLocaleLowerCase(); + } + if (haystack.includes(normalizedNodeSearch)) { matches.add(node.id); }