Skip to content
This repository has been archived by the owner on Nov 9, 2020. It is now read-only.

Large difference in size for a number of enum types #136

Open
erickt opened this issue Jul 12, 2017 · 1 comment
Open

Large difference in size for a number of enum types #136

erickt opened this issue Jul 12, 2017 · 1 comment

Comments

@erickt
Copy link
Contributor

erickt commented Jul 12, 2017

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.

@andrewjstone
Copy link
Contributor

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants