Skip to content

Optimization opportunity: encoded_len gets computed twice when encoding a message聽#1112

Description

@ivoanjo

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:

image

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 馃檹

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions