quick-protobuf
quick-protobuf copied to clipboard
Use bytes crate instead of std::cow?
I'm curious whether you've considered using the bytes crate for handling of &[u8]
buffers should also allow to get rid of std::cow
for strings. This might provide for a nicer and cleaner user-interface and is potentially even more efficient due to efficient access of a single buffer for all of a protobuf message.
I am not sure it'll be more efficient. Yes I have considered it and it looks like a good alternative indeed. I just don't have enough time to explore properly what are all the implications.
I had a branch to add an option to pb-rs
to generate code with bytes instead of std::cow
, but I never opened a PR b/c it looked like it hurt performance a bit. I can look at reviving the branch and posting the benchmark.
To be honest I'm actually a bit in conflict with bytes
: On one hand the crate is super useful for all async IO stuff (e.g. Tokio and Actix) on the other hand it's a similar PITA as std::cow
for embedded. When I opened the ticket I was not quite aware that it actually seems to be possible to make quick-protobuf
#[no_std]
. Ultimately I'd actually prefer that.
re: this issue and https://github.com/tafia/quick-protobuf/pull/142.
There's already a flag for generating code without Cow
: --dont_use_cow
. It seems like the intention of that flag is no_std
. Should there be a --no-std
flag that disables Cow
and disables Owned
together?
Any chance of making this an option at least when working directly with quick-protobuf
directly? I have the issue right now that I am trying to pass in Bytes
and would like to get them back for zero-copy, but can't because the interfaces require me to pass in &[u8]
.