Search code examples
simdzig

what is dark magic behind meta.Vectors?


After implementing some vector algebra based on generic algorithms and iterators, I decided to run some benchmarks. The idea was to compare custom vectors' with meta.Vectors' performance (doing addition and scaling).

When vectors' size was set to 10, custom vectors slightly outperformed meta.Vectors. When vectors' size was set to 100, meta.Vectors slightly outperformed custom vectors. When vectors' size was set to 1000, custom vectors performed addition twice as slowly as meta.Vectors and scaling -- slightly more slowly than meta.Vectors (using @splat).

Funniest thing is compilation times -- those grew with vectors' size growth (didn't measure, can't tell if compilation time was linear in vectors' size). When vectors' size was set to 10_000, I eventually (after a long wait) received shell returned 137 error message (during compilation); after I've commented out any mention of meta.Vector, code compiled just fine.

So my question is what kind of (compiler?) dark magic makes 1000-sized meta.Vectors work so fast and can I use it to make my code faster?

P. S.: benchmarks were run with -O ReleaseFast, all variables were marked var

P. P. S.: in debug mode code with 10_000-sized meta.Vectors eventually compiled


Solution

  • AFAIK all it does is explicitly leverage LLVM's SIMD support.

    https://ziglang.org/documentation/0.8.0/#Vectors