Hey 馃憢! I work at Datadog and we use prost in our libdatadog rust component.
While looking at some performance profiling of our protobuf encoding, I noticed that there's quite a bit of repeated work between encode and encode_raw since both need encoded_len, and it gets computed twice:

Specifically, Message::encode computes the encoded_len to check if the buffer has enough space, and then throws this info away, and then encode_raw gets the number again as it needs to record the field size in the pprof.
Computing encoded_len is around 5% of the time of this benchmark, so there would be a nice gain in encoding speed if it was computed only once.
We're happy users of prost so I decided to report this in the spirit of "see something, say something".
Thanks again for your amazing work so far 馃檹
Hey 馃憢! I work at Datadog and we use prost in our libdatadog rust component.
While looking at some performance profiling of our protobuf encoding, I noticed that there's quite a bit of repeated work between
encodeandencode_rawsince both needencoded_len, and it gets computed twice:Specifically,
Message::encodecomputes theencoded_lento check if the buffer has enough space, and then throws this info away, and thenencode_rawgets the number again as it needs to record the field size in the pprof.Computing
encoded_lenis around 5% of the time of this benchmark, so there would be a nice gain in encoding speed if it was computed only once.We're happy users of prost so I decided to report this in the spirit of "see something, say something".
Thanks again for your amazing work so far 馃檹