Problem Statement / Feature Objective
The current Canvas 2D topology renderer drops below 10 FPS when rendering 5 000+ nodes with edge connections due to CPU-side layout calculations and draw-call overhead. Migrating the force-directed layout and rendering to WebGPU compute shaders enables smooth 60 FPS rendering at 10 000+ nodes by offloading the Barnes-Hut n-body simulation to the GPU.
Technical Invariants & Bounds
- Node count range: 1 000 to 10 000 (practical limit for enterprise networks)
- Edge count: up to 3 times nodes (typical connectivity)
- Target FPS: 60 (16.6 ms per frame budget)
- WebGPU compute shader workgroup size: 256
- Barnes-Hut theta threshold: 0.5
- Fallback: WebGL2 if WebGPU unavailable; Canvas 2D as last resort
Codebase Navigation Guide
- src/components/network/TopologyCanvas.tsx -- current Canvas 2D renderer
- src/lib/graph/layoutEngine.ts -- current CPU force-directed layout
- src/lib/webgpu/graphShaders.wgsl -- proposed compute shader source
- src/lib/webgpu/webgpuEngine.ts -- proposed WebGPU wrapper (device, queue, pipeline init)
- src/hooks/useTopologyData.ts -- existing hook feeding node/edge data
Implementation Blueprint
- Create wgsl/graphShaders.wgsl with two compute shaders: (a) barnesHut -- computes node-node forces using a quadtree built in shared memory; (b) integrate -- updates velocity and position with damping.
- Build webgpuEngine.ts that initializes a GPUDevice via navigator.gpu.requestAdapter() and adapter.requestDevice(), creates a compute pipeline from the WGSL shaders, and manages GPUBuffer pairs for position/velocity double-buffering.
- Refactor layoutEngine.ts to detect WebGPU support via useWebGPUAvailable() hook. If available, upload initial node positions to GPU buffers, dispatch compute shaders each frame, read back positions via a staging buffer, and pass them to the renderer. If unavailable, fall through to the existing CPU path.
- Modify TopologyCanvas.tsx to use webgpuEngine.output.positionBuffer mapped to a GPURenderPipeline for drawing circles/lines directly on the GPU (use a full-screen quad with vertex shader reading from storage buffer).
- Implement adaptive quality: when GPU frame time exceeds 14 ms, reduce rendered nodes by 25 % (hide low-importance leaf nodes) and display a quality badge.
- Benchmark with a synthetic 10 000-node dataset: assert FPS >= 55. Use Chrome DevTools Protocol CDP Performance.enable for automated measurement in CI.
Problem Statement / Feature Objective
The current Canvas 2D topology renderer drops below 10 FPS when rendering 5 000+ nodes with edge connections due to CPU-side layout calculations and draw-call overhead. Migrating the force-directed layout and rendering to WebGPU compute shaders enables smooth 60 FPS rendering at 10 000+ nodes by offloading the Barnes-Hut n-body simulation to the GPU.
Technical Invariants & Bounds
Codebase Navigation Guide
Implementation Blueprint