4 ms·
Rust 1.78: Performance Impact of the 128-Bit Memory Alignment Fix
- vardump 2y agoI'm surprised a Rust alignment bug is fixed this late. Performance degradation issues due to bad alignment is usually pretty obvious and somewhat easy to notice. I'm assuming vectorized (SSE) code is often generated for 128-bit loads and stores. Obviously something must have obscured it until now. Anyone knows why? Edit: So it was an LLVM issue. Even weirder. https://reviews.llvm.org/D86310 https://reviews.llvm.org/D86310 Edit2: Ok, it's obvious: if you "fix" something like this you can break a lot of code that relies on specific struct alignment. Ouch.
- Jalad 2y agoI'm guessing that it's because u128 / i128 are used less frequently than primitives with smaller bit counts. Could be something else though
- viraptor 2y agoThat and also if you already have other large values, half the time you'd hit the right alignment by accident. Sometimes consistently every time in your app if you're lucky.
- willglynn 2y agoThe best treatment is at: https://blog.rust-lang.org/2024/03/30/i128-layout-update.html https://blog.rust-lang.org/2024/03/30/i128-layout-update.htm... Note also that this involves LLVM, so clang < 18 had the same u128 behavior as Rust < 1.77/1.78.
- lpribis 2y agoNo, clang never had this issue since they bodged it in the front-end. From the post you linked: > Clang uses the correct alignment only because of a workaround, where the alignment is manually set to 16 bytes before handing the type to LLVM. Maybe it took long to notice because it was assumed to be working in LLVM since clang worked?
- turndown 2y agoIn addition to the other linked post, this one https://faultlore.com/blah/abi-puns/ https://faultlore.com/blah/abi-puns/ would give you a good idea of how this bug in LLVM was found
- wiktor-k 2y agoIs it just me or should the following fragment use EnforcedAlignment in main? #[derive(TypeLayout, Copy, Clone)] #[repr(C)] struct EnforcedAlignment { _offset: [u8; GAP - 8], data: AlignedU128, } pub fn main() { println!("{}", StockAlignment::type_layout()); } Excellent blogpost showing their product, by the way!
- adriencaccia 2y agoHey, co-author of the article here! You are completely right, this is a typo, I will fix it asap! Thanks for the kind words