Skip to content

More efficient Rust compiler optimization barriers

License

Notifications You must be signed in to change notification settings

HadrienG2/pessimize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pessimize - More efficient Rust compiler optimization barriers

MPL licensed Package on crates.io Documentation Continuous Integration Requires rustc 1.79.0+

Microbenchmarking is a subtle exercise to begin with, and the lack of lightweight optimization barriers on stable Rust makes it even more difficult. This crate aims to improve upon the statu quo by providing an alternative to std::hint::black_box which is...

  • As lightweight as a library-based approach can be
  • Fine-grained, enabling precise intent statement and thus lower overhead
  • Reliable (no more "this might do nothing on some compiler targets", if it compiles then it should work as advertized).

In exchange, the price to pay is...

  • Reduced microbenchmark portability (currently 32-bit and 64-bit flavors of ARM, x86 and RISC-V, more can be envisioned on nightly / future stable Rust)
  • Lots of unsafe code in the implementation (we often need to convert an std type with safety invariants to a simpler data structure with less safety invariants, pass the members of this data structure through an optimization barrier that does nothing, then convert it back to the original type).