| Crates.io | vibe-graph-layout-gpu |
| lib.rs | vibe-graph-layout-gpu |
| version | 0.1.0 |
| created_at | 2026-01-21 00:56:32.055986+00 |
| updated_at | 2026-01-21 00:56:32.055986+00 |
| description | GPU-accelerated force-directed graph layout using WebGPU/wgpu |
| homepage | |
| repository | https://github.com/pinsky-three/vibe-graph |
| max_upload_size | |
| id | 2057937 |
| size | 101,695 |
GPU-accelerated force-directed graph layout using WebGPU/wgpu.
| Graph Size | Traditional CPU | GPU Barnes-Hut | Speedup |
|---|---|---|---|
| 1,000 nodes | ~10 FPS | 185 FPS | ~18x |
| 9,000 nodes | ~1 FPS | 110 FPS | ~110x |
| 10,000+ nodes | <1 FPS | 60+ FPS | >60x |
The layout uses a modified Fruchterman-Reingold force-directed algorithm with:
The Barnes-Hut algorithm reduces force calculation complexity from O(n²) to O(n log n):
use vibe_graph_layout_gpu::{GpuLayout, LayoutConfig, Position, Edge};
// Create positions and edges
let positions = vec![
Position::new(0.0, 0.0),
Position::new(100.0, 0.0),
// ...
];
let edges = vec![
Edge::new(0, 1),
// ...
];
// Initialize GPU layout
let config = LayoutConfig {
use_barnes_hut: true,
theta: 0.8,
..Default::default()
};
let mut layout = pollster::block_on(GpuLayout::new(config))?;
layout.init(positions, edges)?;
// Run simulation
layout.start();
loop {
let updated_positions = layout.step()?;
// Render positions...
}
┌─────────────────────────────────────────────────────────────┐
│ CPU Side │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Graph Data │───▶│ Quadtree │───▶│ GPU Buffers │ │
│ │ (positions) │ │ (Barnes-Hut)│ │ (upload) │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ GPU Side │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Repulsive │───▶│ Attractive │───▶│ Integrate │ │
│ │ Forces │ │ Forces │ │ Positions │ │
│ │ (BH approx) │ │ (edges) │ │ │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────────┘
The crate compiles to WebAssembly and uses WebGPU:
cargo build --target wasm32-unknown-unknown -p vibe-graph-layout-gpu
# Simple 1000-node test
cargo run --example simple_layout
# Large 9000-node benchmark (matches mathlib4 scale)
cargo run --example large_graph --release
| Parameter | Default | Description |
|---|---|---|
dt |
0.016 | Time step per iteration |
damping |
0.9 | Velocity damping (0-1) |
repulsion |
1000.0 | Node repulsion strength |
attraction |
0.01 | Edge attraction strength |
theta |
0.8 | Barnes-Hut threshold (0.5-1.0) |
gravity |
0.1 | Center gravity strength |
ideal_length |
50.0 | Target edge length |
max_tree_depth |
12 | Quadtree depth limit |
MIT