How fast is go? simulating millions of particles on a smart tv
The challenge, simulate millions of particles in golang, multi-player enabled, cpu only, smart tv compatible.
Let's go, pun very much intended.
So, during my day job I had to write a ws server which merged multiple upstream ws servers into a single ws server. (Don't ask) I was lost and not even the power of claude, gemini, and cursor could save me. The vibes were simply not enough to get the project done. I had to learn the real real stuff.
To learn the real stuff I decided to write a particle simulation and see how many particles I could get golang to push. I had already done this in the lands of javascript, rust, and swift. But given Go doesn't support simd, I knew it wouldn't be a fair fight against the other languages and more importantly, it would be boring let alone helping my day job.
I figured to give go the best shake I needed to up the difficulty by adding multi-player to the simulation. After all, go is best known as a snappy productive backend language. Is it snappy and productive enough for simulating a million particles and syncing it across hundreds of clients?
Only one way to find out.
This is a long read, if you want to play around with a multi-player enabled particle sim, go to howfastisgo.dev. Or play around with the title at the top, it is an iframe to the live website.
For those interest, the code is on github. I did fix a bug when clients disconnect and bumped it up to 4m particles. Enjoy.
No Cheating
... continue reading