Skip to content

Turn any idea, plan, or codebase into a beautiful interactive diagram. An agent skill for Claude Code, Codex, and more.

perf(routing): avoid temporary arrays when counting crossings

cyanseekab9c2e5b54f9
diff --git a/archify.zip b/archify.zip
index 59b52548..d0576161 100644
Binary files a/archify.zip and b/archify.zip differ
diff --git a/archify/renderers/architecture/routing.mjs b/archify/renderers/architecture/routing.mjs
index 3f4a2792..97e2e605 100644
--- a/archify/renderers/architecture/routing.mjs
+++ b/archify/renderers/architecture/routing.mjs
@@ -983,12 +983,22 @@ export function createRouter(components, connections = [], {
}
function crossingCount(conn, points, resolvedRoutes) {
- return resolvedRoutes.reduce((total, entry) => total + Number(
- !(relationshipsShareEndpoint(conn, entry.conn)
- && (!distinctAutomaticPorts || hasAuthoredRouteGeometry(entry.conn) || entry.conn.labelAt || conn.labelAt))
- && points.slice(1).some((end, index) => entry.points.slice(1).some((otherEnd, otherIndex) =>
- properSegmentIntersection(points[index], end, entry.points[otherIndex], otherEnd))),
- ), 0);
+ let count = 0;
+ for (const entry of resolvedRoutes) {
+ if (relationshipsShareEndpoint(conn, entry.conn)
+ && (!distinctAutomaticPorts || hasAuthoredRouteGeometry(entry.conn) || entry.conn.labelAt || conn.labelAt)) continue;
+ let crosses = false;
+ for (let index = 1; index < points.length && !crosses; index += 1) {
+ for (let otherIndex = 1; otherIndex < entry.points.length; otherIndex += 1) {
+ if (properSegmentIntersection(points[index - 1], points[index], entry.points[otherIndex - 1], entry.points[otherIndex])) {
+ crosses = true;
+ break;
+ }
+ }
+ }
+ if (crosses) count += 1;
+ }
+ return count;
}
function readabilityCost(conn, routed, resolvedRoutes) {