prost icon indicating copy to clipboard operation
prost copied to clipboard

Allow using `Box<[u8]>`/`Box<str>` for `bytes`/`string` fields

Open poliorcetics opened this issue 1 year ago • 4 comments

This reduces the size of objects by one byte each time they're used, which can help quite a lot in some cases.

This is fully optional and the defaults have not changed.

poliorcetics avatar Jun 30 '23 17:06 poliorcetics

I saw https://github.com/tokio-rs/prost/issues/429 but it's not what I wanted since it asks for two levels of indirection, Arc<Vec<u8>> for example.

I can probably easily add Arc<str> and Arc<[u8]> if necessary though

poliorcetics avatar Jun 30 '23 17:06 poliorcetics

I tried to implement this in an external lib but it's inefficient if done naively (conversions to String/Vec<u8>) everywhere and since prost doesn't expose its helpers to build Messages, doing it efficiently means copying a lot of code that is intended for internal use only and is quite brittle when used in another crate.

poliorcetics avatar Jul 08 '23 16:07 poliorcetics

Please merge this, would be extremely helpful.

michaelvanstraten avatar Aug 16 '23 16:08 michaelvanstraten

Rebased to fix conflicts, no actual changes made

poliorcetics avatar Sep 02 '23 22:09 poliorcetics

It seems like https://github.com/tokio-rs/prost/pull/979 is interesting for this PR. It would simplify the encoding needed for Box<str> support, am I right?

caspermeijn avatar May 31 '24 10:05 caspermeijn

I'm not working with prost anymore and this PR is way out of date, someone interested can retake it if necessary :)

poliorcetics avatar Jun 03 '24 12:06 poliorcetics