I'm coming from golang.
In Golang there is a fieldalignment project which aligns fields for a better performances (Saving a Third of Our Memory by Re-ordering Go Struct Fields | Lane's Blog ).
Is in Rust something similar?
It's needed? Or the compiler aligns fields itself for better performances?
H2CO3
May 22, 2022, 10:33am
2
The layout of all non-#[repr(C)]
types is unspecified exactly for this reason. I do recall seeing that the compiler performs some sort of field reordering for making structs smaller.
Here's a small playground that demonstrates field reordering.
3 Likes
bjorn3
May 22, 2022, 10:36am
3
Indeed. Rust has been reordering struct fields to reduce padding for years now. See
https://github.com/rust-lang/rust/pull/37429
6 Likes
Or here's a prose writeup about it:
5 Likes
What a pleasure this language and what a pleasure this community of wonderful people! Thank you so much!
I choose the first answer as the solution, for the speed.
1 Like
system
Closed
August 22, 2022, 12:47pm
6
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.