I made Zig compute 33M satellite positions in 3 seconds

atempleton.bearblog.dev

138 points by signa11 12 hours ago


tylermw - 7 hours ago

Nice results! SIMD can be a pain, good to know Zig makes it easy.

However, note that the plot under "Native SIMD Throughput Comparison" is extremely misleading: for an accurate proportional comparison between bar charts, you should start the y-axis at zero. The way the data are presented makes it look like a 10-100x gain, rather than the actual 2x improvement.

lbeckman314 - 4 hours ago

Beautiful visualization at https://attron.github.io/astroz-demo! (~160 MB transfer)

My (very amateur) belief is that we're in a quiet golden age of cool space viz/tools, for example:

- https://www.asterank.com/3d

- https://dmytry.github.io/space/

- https://www.tng-project.org/explore/3d

- https://github.com/da-luce/astroterm

- https://ssd.jpl.nasa.gov/tools

Feels like the halcyon techno-optimism from TOS + TNG!

notthemessiah - an hour ago

This compares it to Python and Rust implementations, I wonder how it compares to Julia's SatelliteToolbox.jl? Julia also compiles to LLVM and has macros for explicit SIMD.

https://github.com/JuliaSpace/SatelliteToolbox.jl

exitb - 5 hours ago

Is that solving the right problem? The algorithm can give reasonably accurate positions at arbitrary points in future, but you don’t need to run it over and over if you need positions every second. You can generate keyframes and interpolate the positions between, as the short term orbital movements are rather trivial.

philipallstar - 7 hours ago

I've never seen SIMD code before, and this is quite a nice little intro into that and Zig.

ww520 - an hour ago

Nice to have a huge speed up. Kudos for applying the right tools and right approaches to get it done. I especially like your explanation of how to utilize SIMD in Zig. Learned something today.

dfajgljsldkjag - 7 hours ago

It is funny how we often assume we need a graphics card for these kinds of calculations when a standard processor is actually plenty fast. The specific changes to the memory layout seemed to make the biggest difference here by allowing the hardware to actually use its vector capabilities.

ginko - 5 hours ago

There's one example given where either the result of a simple or complex calculation is picked depending on eccentricity mentioning it's faster to just always calculate both and picking with a mask.

If you calculate both, wouldn't it be even faster to just always do the complex calculation? (presumably that's more precise?)

androiddrew - 6 hours ago

You tell that language what to do!