Skip to content

Implement Spatial Partitioning for Large Graphs #45

@lowhung

Description

@lowhung

Description

The current force-directed layout uses O(n²) all-pairs repulsion calculation. For graphs with 500+ nodes, this will become a performance bottleneck.

Current State

// src/ui/layout.rs:60-82
for i in 0..nodes.len() {
    for j in (i + 1)..nodes.len() {
        // O(n²) comparison
    }
}

Proposed Solution

Implement Barnes-Hut algorithm using a quadtree:

  1. Build quadtree of node positions each frame
  2. For distant node clusters, approximate as single point mass
  3. Only compute exact forces for nearby nodes
  4. Reduces complexity to O(n log n)

Acceptance Criteria

  • Implement quadtree data structure
  • Implement Barnes-Hut approximation (theta parameter ~0.5)
  • Add benchmark comparing O(n²) vs O(n log n) for various graph sizes
  • Fallback to simple algorithm for small graphs (<100 nodes)
  • No visual regression for typical graph sizes

Files Affected

  • src/ui/layout.rs
  • New: src/ui/layout/quadtree.rs (optional)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions