Why the compiler does not optimize to the best Assembly possible?
⚓ Rust 📅 2026-01-17 👤 surdeus 👁️ 1I know that the Rust compiler will optimize struct fields order automatically. Considering these C++ and Rust code
C++ does not optimize struct fields order as you can see it writes 4 byte, then 8 byte, then 4 byte which is not good
Zig is same
Rust one does some optimization. It only write to memory 2 times, because memory is slow so avoiding it makes thing faster
But that is not the best one. Considering the next pics
Now C++ has better output than Rust. It does not writes to memory at all, but it uses register completely
Zig is same
Rust can achieve the same but it requires hack that almost no Rust user uses it when I see their code from Github, whether library or personal project
My question is why the Rust compiler does not optimize it to the best one?
4 posts - 4 participants
🏷️ Rust_feed





