-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize enum layout #20638
Comments
Interestingly: fn main() {
enum X { A, B(u64, u32) }
enum Y { A, B(u32, u64) }
assert_eq!(std::mem::size_of::<X>(), 24);
assert_eq!(std::mem::size_of::<Y>(), 16);
} I don't know much about llvm, but I would maybe guess some sort of optimization is going on |
@frewsxcv Those sizes are what one would expect without any kind of optimisation: |
@Diggsey Awesome, thanks for the clarification 👍 . I'm not experienced in this lower level way of thinking |
@Diggsey also, for X, 1 + 7 + 8 + 4 != 24 |
Nevermind, missed that last |
NP, you had me worried for a second there... |
@mahkoh to be clear, are you suggesting that the compiler should reorder fields to try to make enums as small as possible? |
Isn't that the point behind leaving the layout undefined? |
I'll take that as a yes. Thanks for clarifying. |
This particular enum can be optimized without reordering fields. Reordering is just one method to find an unused byte. |
Some of which we should only do with |
The text was updated successfully, but these errors were encountered: