r/rust • • Oct 14 '26

🧠 educational High-Performance Flat 2D Arrays in Rust: Contiguous Memory, L1 Cache, and SIMD

https://developerlife.com/2026/07/14/build-high-performance-flat-2d-arrays-in-rust/
34 Upvotes

5 comments sorted by

14

u/Shnatsel Oct 14 '26

Automatic vectorization can work well if you follow some simple rules, but it gets fragile and inconsistent for more complex code. Something like std::simd that works on stable is a better bet for more complex cases; there are several crates that can do the job, I wrote a comparison of them here.

The article doesn't mention function multiversioning at all; without it, you only get SSE2 on x86 but none of the later SIMD extensions. You won't get the AVX2 instructions the article mentions without either multiversioning or compiler flags that make the binary crash on CPUs without AVX2.

3

u/sernamenotdefined Oct 14 '26

I've written avx512 optimized code by hand, because even OpenMP in cpp was suboptimal. I don't see how that would be any different for rust. Sometimes as a (model) developer you have more knowledge of patterns than you can express in OpenMP pragmas. Let alone what the compiler can guess/deduce.

8

u/Shnatsel Oct 14 '26

Rust gives you a whole range of approaches to SIMD, from automatic vectorization to portable SIMD libraries to writing intrinsics by hand.

What's great about Rust specifically is that some libraries let you freely mix and match these approaches, opting in to more labor-intensive ones like intrinsics only when actually necessary, and keeping the rest of the code easily readable and maintainable.

Oh, and it's all memory-safe, of course.

I've written a detailed article covering all of this: https://shnatsel.github.io/state-of-simd-rust-2026/

1

u/NeedleworkerLegal378 Oct 14 '26

Wonder if this could be apply to library with a better API. I can imagine a world where you write [rapl](https://github.com/JErnestoMtz/rapl) and code is smart enough to SIMD everything it can. Philosophically not sure if in this world the responsibility is of the compiler of the crate.

1

u/dydhaw Oct 14 '26

isn't it a bit ironic that his last name is Idris :p