Choice can be a drag. For finding movies in particular, I don’t think modern interfaces help at all. Oftentimes, I feel as if the correct movie exists, and it just has to be found. If it feels like navigation, then why not make a map out of it?
A picture is worth a thousand words. Of course people use it in artistic contexts, but its relevance to data visualization is just as potent. In fact, unlike art, great data visualization often has a very mechanistic interpretation to front an unambiguous argument. The presented truth comes from the fact that data is just reshaped to be useful. Sometimes a story emerges that no one had on their radar. For example, John Snow’s Broad Street Cholera Map clearly shows that cholera comes from sewage and not “bad air”. While movies rarely have life-saving insight (as far as we know), I’d like to think that psychological insight is latent in movie preferences.
Modern web interfaces are kinda drab because they feel like databases. Not much in the design separates the UI from the data. Especially when it comes to picking films, there have been too many instances where I just scrolled and scrolled without finalizing a choice. “Thank you, next” as Ariana Grande might say.
I decided to turn this into a realtime rendering problem. My initial terse formulation was something like, “there are 65,000-ish films in the Kaggle dataset, and I’d like to interactively render all of them in a force-directed graph” (Fruchterman & Reingold 1991). The goal was to make exploring the movies like wandering through a map. The first step is nailing the early phases of the graphics pipeline, mainly the simulation of the nodes.
Force-Directed Graphs
Force-directed graphs are a technique to visualize recursive data structures. They’re very popular, I’ll have you know.
Basically, it is a particle simulation. Every particle is a node. The nodes repel like electrons (all to all). Linked nodes are treated as springs and attract each other. This problem is textbook $ O(N^2) $ time complexity for the basic implementation and is very parallel by nature. To get a feeling of cost, with an $ O(N^2) $ algorithm 65,000 bodies each computing pairwise forces against each other is billions of interactions each with thousands of instructions per second.
Barnes-Hut for Repulsion
The repulsive force of one node is a sum of its repulsion against all other nodes. Barnes & Hut (1986) proposed using a quadtree to compute forces on collections of neighboring particles rather than every one individually. The technique is very popular and relatively straightforward to implement.
Given the goal of having it be realtime, it has to run on the gpu. One of the banes of GPU programming is branchy and recursive code. Even though it is possible to implement using recursion, GPU implementations often push and pop nodes onto a stack instead (Burtscher & Pingali 2011). Modern GPUs have hardware acceleration for tree construction and traversal. Though these are for BVHs and ray tracing, recent research has explored their application in particle simulation (Zhu 2022; Nagarajan et al. 2025). I may implement this at a future date.
Brute Force for Attraction
For attractive forces, things get a little tricky. Unlike the all-to-all nature of repulsion, attractive forces are inherently sparse and irregular. I have an implementation where nodes are read into threadgroup memory, and forces are computed pairwise in batches. This technique is a small alteration of the technique proposed by Nyland et al. (2007).
Modern GPUs don’t really execute one thread at a time. They execute groups of threads together in lockstep. On Apple Silicon GPUs that group consists of 32 lanes, called a SIMD-group (a warp on Nvidia). Instead of pretending each thread is an independent worker, I structured much of both the simulation and rendering to operate in 32 sized groups.
For the particle simulation, this mostly shows up in reductions and broadcasts. Computing the bounding box, for example, doesn’t have every thread writing into shared memory. Each lane computes a local minimum and maximum before the entire SIMD-group reduces those values using simd_min() and simd_max(). Only lane zero performs the final write back to memory.
topLeftX = simd_min(topLeftX);
topLeftY = simd_max(topLeftY);
bottomRightX = simd_max(bottomRightX);
bottomRightY = simd_min(bottomRightY);
if (simd_lane_id == 0) {
topLeft.data[0].x = -0.99f;
topLeft.data[0].y = 0.99f;
bottomRight.data[0].x = 0.99f;
bottomRight.data[0].y = -0.99f;
}
I use the same pattern when computing the center of mass for each Barnes-Hut node. Every lane accumulates mass for a subset of particles, then the SIMD-group combines the partial sums before a single lane writes the result back to memory.
M = simd_sum(M);
R.x = simd_sum(R.x);
R.y = simd_sum(R.y);
if (simd_lane_id == 0 && M > 0.0f) {
R /= M;
totalMass.data[nodeIndex] = M;
centerOfMass.data[nodeIndex] = R;
}
I wanted the graph to have a neuron-like appearance. Every edge has to blend smoothly into the previous and next edge around a node, so each thread needs information about its neighbors. A traditional vertex shader is a poor fit for this problem because every vertex is processed independently. Recovering neighboring information would require additional memory reads, often loading the same data multiple times.
Object and mesh shaders (Apple 2022) offer a more data-centric programming model: an entire threadgroup cooperates to generate a small piece of the graph, with each thread constructing the geometry for a single half-edge.
Before rendering, a compute pass sorts the half-edges by their source node - two buffers each representing the source and target node.
- The source node buffer is grouped by index: A,A,A,A,B,C,C,C,C
- The target nodes are radix sorted by angle to go clockwise.
This means neighboring threads usually process neighboring edges in memory, which gives much better cache locality and, more importantly, lets threads cooperate. Is there a better criterion for sorting? Maybe.
Each lane computes the geometry for its edge: its midpoint, tangent, and perpendicular offset. Instead of loading the previous or next edge from device memory, those values are exchanged directly between neighboring lanes using SIMD shuffle instructions (hence the angle sort pass). The data never leaves the SIMD-group and synchronization primitives are avoided.
float2 prevMidpoint = simd_shuffle_up(midpoint, 1);
float2 nextMidpoint = simd_shuffle_down(midpoint, 1);
float2 prevJoint = simd_shuffle_up(joint, 1);
float2 nextJoint = simd_shuffle_down(joint, 1);
Of course, this only works while neighboring edges happen to live inside the same SIMD-group. Nodes with a very large degree span multiple groups, while nodes with only a handful of edges leave unused lanes. Whenever a SIMD-group crosses one of these boundaries, the resulting seam means the missing neighbor has to be pulled from memory. Fortunately, as the number of nodes being rendered increases so does the coherency and utilization.
What’s Next?
At the moment, the priority is getting everything running smoothly. I’ve heard that premature optimization is a dangerous game, and maybe I’ve focused too much effort at this stage. Anyway.

References
- Fruchterman, T. M. J. and Reingold, E. M. 1991. Graph Drawing by Force-directed Placement. Software: Practice and Experience 21(11), 1129-1164.
- Barnes, J. and Hut, P. 1986. A hierarchical O(N log N) force-calculation algorithm. Nature 324, 446-449.
- Burtscher, M. and Pingali, K. 2011. An Efficient CUDA Implementation of the Tree-Based Barnes Hut n-Body Algorithm. In GPU Computing Gems, ch. 6, 75-92. Elsevier.
- Nyland, L., Harris, M., and Prins, J. 2007. Fast N-Body Simulation with CUDA. In GPU Gems 3, ch. 31. NVIDIA.
- Zhu, Y. 2022. RTNN: Accelerating Neighbor Search Using Hardware Ray Tracing. PPoPP ‘22.
- Nagarajan, V., Gangaraju, R., Sundararajah, K., Pelenitsyn, A., and Kulkarni, M. 2025. RT-BarnesHut: Accelerating Barnes-Hut Using Ray-Tracing Hardware. PPoPP 2025.
- Apple. 2022. Transform your geometry with Metal mesh shaders. WWDC22, session 10162.