Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use references to represent string/bytes proto3 field types #1113

Open
pushkarmoi opened this issue Jul 31, 2024 · 1 comment
Open

use references to represent string/bytes proto3 field types #1113

pushkarmoi opened this issue Jul 31, 2024 · 1 comment

Comments

@pushkarmoi
Copy link

Hi folks,

prost currently uses owned objects is String and Vec<u8> in code generated structs for proto3 string and bytes fields.

This can add considerable performance overhead for -

  1. Serialization: We currently store utf8 in custom in memory data structures. To construct a serializable prost struct, we need to deep copy the data to create owned String objects. Allowing us to pass &str or Cow<&str> (like https://github.com/tafia/quick-protobuf) will help a lot. The deep copying is a major consumer of cpu cycles as per flamegraph

  2. Deserialization: We anticipate there's a similar issue there with prost deep copying utf8 out of underlying bytes to create the String struct fields. We benchmarked quick-protobuf and it outperformed prost in this aspect - i believe it doesn't need to deep copy the actual string bytes.

Understand this can be incompatible api wise so an opt in config might be best to support it.

Thanks!

@caspermeijn
Copy link
Collaborator

Hi @pushkarmoi

I understand your concerns. I have a plan to make the types used in generated fields more configurable. Cow<&str> could be one of the new types. However, I currently have not the bandwidth to work on that.

If you are willing to contribute (time or money), please contact me to figure out the details.

Thanks, Casper

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

No branches or pull requests

2 participants