Skip to content

perf(erd): spatial hashing for hover edge hit-testing and viewport culling on canvas #1534

Closed as not planned

Description

@ZhuchkaTriplesix

Problem

In ErdView (lib/features/erd/erd_view.dart):

  1. 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.
  2. 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.

Activity

  1. ZhuchkaTriplesix commented on Oct 12, 2026

    @ZhuchkaTriplesix
    MemberAuthor

    Closing after measuring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions