branches 0.4.0: an optimization crate good to shoot yourself in the foot!

71 points fereidani 16 comments

Hey everyone!

I'm excited to announce the release of branches 0.4.0(https://github.com/fereidani/branches), a small #![no_std] compatible crate for low-level performance optimizations in Rust.

I haven't publicly posted about branches until now because I'm worried that incorrect usage could degrade performance, and getting it right can be quite tricky.

branches provides helpers for:

  • Branch prediction hints (likely() and unlikely())
  • Unsafe control flow assumptions (assume())
  • Immediate process abort (abort())
  • Manual data prefetching (read/write with configurable locality)

These use stable Rust somewhat equivalent implementation and falling back to core::intrinsics on nightly.

When used correctly, these can give your hot loops a nice speedup… but if you get them wrong and believe me, most of the time everyone including me do, you end up making things worse!

As peter's wise uncle once said: "With great power comes great irresponsibility."

What's new in 0.4.0?

  • Made "prefetch" an optional feature

Links

Give it a star if you liked it!
Feedback, bug reports, and PRs very welcome!

Let's make Rust even faster (safely... mostly).
Thanks! 🚀