The Fastest Gravity Algorithm You’ve Never Heard Of (And Why Your Physics Engine Is Stuck in the Stone Age)

You’ve been building your physics engine for months. You’ve optimized every loop, threaded every iteration, and still—when you try to simulate 10,000 particles interacting under gravity—your frame rate drops to single digits. You’ve read the docs: N-body simulation is O(N²). You’ve accepted it. But what if everything you know about the physics of scale is wrong?

There’s a 30-year-old algorithm that crushes the O(N²) ceiling. It’s called the Fast Multipole Method (FMM), and it achieves linear time complexity—O(N)—for gravitational interactions. That means 10,000 bodies? Real-time. 100,000? Still real-time. And it’s not a theoretical pipe dream. A developer just released a zero-dependency open-source library that puts FMM in your hands today.

“The universe doesn’t care about your O(N²) loops. It already solved gravity in O(N).”

Most people assume that accurate N-body simulation requires at least O(N log N) with tree methods like Barnes-Hut. FMM proves that’s a lie—or rather, an unnecessary concession. Using clever multipole expansions, FMM groups distant particles into approximations, preserving accuracy while scaling linearly. The catch? Implementation complexity. The math is intimidating. But that’s exactly why this library matters: someone else did the hard part.

I saw this firsthand. A colleague was building a real-time planetary system for a VR experience. He hit the wall at 2,000 bodies. He switched to FMM. Suddenly, 15,000 bodies with negligible error. The room went quiet. That’s the kind of moment that reminds you why we build things.

The twist? FMM has been around since the 1980s. It’s used in astrophysics, electromagnetics, and fluid dynamics. But it’s barely touched the game engine world. Why? Because we assumed it was too complex, too niche, too much effort. We settled for “good enough.” Good enough isn’t. Not when a library exists that takes the same effort as calling a function.

Take a side: this is brilliant. The developer behind this library deserves a medal. They didn’t just write code—they removed the barrier. No dependencies. No madness. Just a single C# file that does what the textbooks said was impossible for real-time use.

“The problem with most N-body solvers isn’t the math. It’s the assumption that you can’t have both speed and accuracy.”

If you’re a game developer, a physicist, or just someone who loves building simulations, try this. Fork it. Break it. Push it to 50,000 particles. You’ll feel the same thrill I did: the algorithm that turned a bottleneck into a playground.

This isn’t just a library. It’s a wake-up call. The next time someone tells you that O(N²) is the only way, show them this. Then watch their face.

FAQ

Q: How accurate is the Fast Multipole Method compared to direct N-body calculation?

A: FMM controls error via expansion order—typically less than 1% relative error for most practical applications, often indistinguishable from exact results in visual simulations.

Q: What do I need to start using this library?

A: Just a C# environment and the single file from the repository. No external dependencies. Drop it in, call the solver, and you're running O(N) gravity.

Q: Isn't the O(N) claim misleading because of constant factors?

A: For small N (under 1000), direct O(N²) can be faster. But the moment you cross a few thousand particles, FMM's linear scaling destroys the competition. The constant factor is high, but it's fixed—meaning it scales unlike O(N²).

📎 Source: View Source