prost icon indicating copy to clipboard operation
prost copied to clipboard

support boxing large/all `oneof` fields

Open xxchan opened this issue 11 months ago • 2 comments

https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant

currently, we can box a variant manually. It would be good to automatically box based on size, or just all variants

xxchan avatar Dec 20 '24 09:12 xxchan

I assume this is about oneof fields.

The prost-derive macros don't have access to the size of a Rust type. So I think it is not possible to automatically box based on size.

Boxing all variants of a oneof field is interesting. Maybe that should happen when the name of the oneof is given to Config::boxed.

caspermeijn avatar Dec 20 '24 09:12 caspermeijn

I don't mind working on this. We can guess the sizes of rust types based on some predefined size and alignment and #[cfg] for pointer sizes. A large enough threshold is enough to not be problematic as boxing a nested message will reduce the size of the field to just the pointer size, freeing up a lot of space to go under the threshold for the current message.

davidzeng0 avatar Feb 19 '25 02:02 davidzeng0