You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(erd): spatial hashing for hover edge hit-testing and viewport culling on canvas #1534
On every mouse move over the canvas (_hoverCanvas), _relationAt iterates through all relation routes (for (final r in _routes)) and tests Euclidean distance to every polyline segment. In complex databases with hundreds of relations, this spikes CPU usage on each pointer movement.
The entire ERD diagram (all cards, frames, and relations) is mounted in a single Stack inside InteractiveViewer without viewport culling. When zoomed in, Flutter continues to layout and render cards that are completely off-screen.
Solution
Index relation routes in a lightweight SpatialGrid or AABB hierarchy to restrict distance testing to only the 1-2 grid cells intersecting the 6px cursor radius.
Implement viewport culling to only mount and render cards and relations intersecting the current visible viewport Rect.
Benefits
O(1) relation hit testing on hover.
Stable 60/120 FPS zoom and pan on diagrams with 200+ tables.
Hover hit-testing (_relationAt) over all routes: ~11 us for 300 relations x 6 points, ~38 us for 1000 relations. That is hundreds of times under a frame budget; a spatial grid is not worth the extra state.
Activity
ZhuchkaTriplesix commentedon Oct 12, 2026
Closing after measuring.
_relationAt) over all routes: ~11 us for 300 relations x 6 points, ~38 us for 1000 relations. That is hundreds of times under a frame budget; a spatial grid is not worth the extra state.