Extended size report#

pw_protobuf: Expressive interface for encoding and decoding protocol buffers

pw_protobuf can impact binary size very differently depending on how it’s used. A series of examples are provided below to illustrate how much certain use cases affect binary size.

Overview#

This module includes a proto encoder, two different proto decoders (one that operates on a pw::stream::StreamReader and another that operates on an in- memory buffer), codegen for direct wire-format encoders/decoders, and a table-based codegen system for constructing proto messages as in-memory structs.

Here’s a brief overview of the different encoder/decoder costs:

Note

The size report that is usually displayed here is temporarily unavailable while we migrate the pigweed.dev build system from GN to Bazel. See b/388905812 for updates.

Note

There’s some overhead involved in ensuring all of the encoder/decoder functionality is pulled in. Check the per-symbol breakdown for more details.

Encoder/decoder codegen overhead#

The different proto serialization/deserialization codegen methods have different overhead. Some have a higher up-front cost, but lower complexity (and therefore smaller compiler generated code) at the sites of usage. Others trade lower up-front code size cost for more complexity at the proto construction and read sites.

This example uses the following proto message to construct a variety of use cases to illustrate how code and memory requirements can change depending on the complexity of the proto message being encoded/decoded.

syntax = "proto3";

package pw.protobuf_size_report;

message ItemInfo {
  enum Access {
    NONE = 0;
    READ = 1;
    WRITE = 2;
    READ_AND_WRITE = 3;
  }
  uint64 offset = 1;
  uint32 size = 2;
  Access access_level = 3;
}

message ResponseInfo {
  oneof key {
    string key_string = 1;
    fixed32 key_token = 2;
  }

  optional int64 timestamp = 3;
  optional bool has_value = 4;
  ItemInfo item_info = 5;
}

message Response {
  repeated ResponseInfo responses = 1;
}

message LookupRequest {
  message AuthInfo {
    optional uint32 id = 1;
    optional uint32 token = 2;
  }
  oneof key {
    string key_string = 1;
    fixed32 key_token = 2;
  }
  optional uint32 items_per_response = 3;
  AuthInfo auth_info = 4;
  bool add_timestamp = 5;
}

This proto is configured with the following options file:


pw.protobuf_size_report.Reponse.responses max_count:4

Trivial proto#

This is a size report for encoding/decoding the pw.protobuf.test.ItemInfo message. This is a pretty trivial message with just a few integers.

Note

The size report that is usually displayed here is temporarily unavailable while we migrate the pigweed.dev build system from GN to Bazel. See b/388905812 for updates.

Optional and oneof#

This is a size report for encoding/decoding the pw.protobuf.test.ResponseInfo message. This is slightly more complex message that has a few explicitly optional fields, a oneof, and a submessage.

Note

The size report that is usually displayed here is temporarily unavailable while we migrate the pigweed.dev build system from GN to Bazel. See b/388905812 for updates.