Comment by jvanderbot

5 hours ago

I do this. I do this a lot. My job involves processing a significant amount of weather data and flight telemetry _very quicky_.

What I have found is that getting rust to auto-vectorize is a nightmare. The options available to me have always converged around: 1) use simd-like apis 2) frame it as matrix-vector operations.

(1) is touched on in TFA

(2) is way easier, and allows use of well-tested apis and crates, each of which (sensibly) call out to better-tested C libraries. Each of those can, should, might, or will use your CPU better than you will. If you can frame it as matrix-vector operations, you will go very fast, not least of which, by stacking the operations into a _big_ matrix/vector op, which your CPU will happily tear though.

However the article proposes a third, very cool option: use algebraic ops API! Worth a read.

   Rust used to not have any reasonable way to do anything like this on stable (for my own definition of reasonable), but now it does! Rust 1.98 stabilized algebraic operators for floats. These allow you to declare per-operation that you’re okay with the compiler making optimizations that may change the result as long as the optimized code is algebraically equivalent to the original. Yes, this includes potentially reordering operations.

> My job involves processing a significant amount of weather data and flight telemetry _very quicky_

That sounds so interesting. Would you be at liberty to share what that job is.

Oh! nevermind, got that off your HN page.

Great insight. My (much less sophisticated) mental model is: 1: I don't know how to get things to auto-vectorize nor evaluate if they did. [I should learn]; I assume they do not. Manual SIMD it is! [I have a lib for floats and vectors which mimics core::simd but on stable and x86 only)

I will check out your insights regarding matrix-vector ops and C libs!

  • Very generally speaking, you want to view dissasembled sections.

    You can do this at the function level.

    In rust, try this: https://github.com/pacak/cargo-show-asm

    However, life is much easier now, because an agent knows how to steer through this with you. Have it teach you at first, then you know how to ask.

    This is one of those "back in my day we had to ... " stories, btw :D