quick-protobuf icon indicating copy to clipboard operation
quick-protobuf copied to clipboard

Use bytes crate instead of std::cow?

Open therealprof opened this issue 5 years ago • 5 comments

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.

therealprof avatar Jun 19 '19 11:06 therealprof

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.

tafia avatar Aug 14 '19 05:08 tafia

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.

nerdrew avatar Aug 23 '19 18:08 nerdrew

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.

therealprof avatar Aug 23 '19 19:08 therealprof

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?

nerdrew avatar Aug 23 '19 23:08 nerdrew

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].

dignifiedquire avatar Dec 04 '22 15:12 dignifiedquire