haret
haret copied to clipboard
Large difference in size for a number of enum types
trafficstars
I'm not sure if this is a big deal or not, but clippy is reporting that a number of variants have large size differences, which can result in lots of wasted space, or excessive memcpys.
warning: large size difference between variants
--> src/admin/messages.rs:13:5
|
13 | Rpy(AdminRpy)
| ^^^^^^^^^^^^^
|
= note: #[warn(large_enum_variant)] on by default
= help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#large_enum_variant
help: consider boxing the large fields to reduce the total size of the enum
| Rpy(Box<AdminRpy>)
warning: large size difference between variants
--> src/admin/messages.rs:36:5
|
36 | ReplicaState(VrState),
| ^^^^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#large_enum_variant
help: consider boxing the large fields to reduce the total size of the enum
| ReplicaState(Box<VrState>),
warning: large size difference between variants
--> src/vr/vr_fsm.rs:82:5
|
82 | Recovery(Recovery),
| ^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#large_enum_variant
help: consider boxing the large fields to reduce the total size of the enum
| Recovery(Box<Recovery>),
warning: large size difference between variants
--> src/msg.rs:15:5
|
15 | AdminRpy(AdminRpy),
| ^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#large_enum_variant
help: consider boxing the large fields to reduce the total size of the enum
| AdminRpy(Box<AdminRpy>),
Are there any downsides on introducing boxes in these structures? This ended up being a big win for the compiler's AST.
The only downside would be allocation overhead. However, for these particular messages, they are used infrequently enough that boxing should allow a net win overall. In the future, they may be restructured enough to not require boxing, but I see no problem with it right now.