Skip to content

Graphs that teach > graphs that impress. Turn any code into an interactive knowledge graph you can explore, search, and ask questions about. Works with Claude Code, Codex, Cursor, Copilot, Gemini CLI, and more.

perf: O(1) edge-category lookup in filterEdges

DashBot-0001068857fb491e
diff --git a/understand-anything-plugin/packages/dashboard/src/utils/filters.ts b/understand-anything-plugin/packages/dashboard/src/utils/filters.ts
index eef3cc29..91a9c349 100644
--- a/understand-anything-plugin/packages/dashboard/src/utils/filters.ts
+++ b/understand-anything-plugin/packages/dashboard/src/utils/filters.ts
@@ -78,11 +78,20 @@ export function filterEdges(
/**
* Determine which category an edge type belongs to
*/
-function getEdgeCategory(edgeType: string): EdgeCategory | null {
+// Reverse index (edge type → category), built once at module load. Replaces a
+// per-edge linear scan over every category's type array — `getEdgeCategory`
+// runs for every edge in `filterEdges`. First category wins, matching the
+// original `Object.entries` scan order.
+const EDGE_TYPE_TO_CATEGORY: Map<string, EdgeCategory> = (() => {
+ const m = new Map<string, EdgeCategory>();
for (const [category, types] of Object.entries(EDGE_CATEGORY_MAP)) {
- if (types.includes(edgeType)) {
- return category as EdgeCategory;
+ for (const t of types) {
+ if (!m.has(t)) m.set(t, category as EdgeCategory);
}
}
- return null;
+ return m;
+})();
+
+function getEdgeCategory(edgeType: string): EdgeCategory | null {
+ return EDGE_TYPE_TO_CATEGORY.get(edgeType) ?? null;
}