pw_protobuf extended size report#
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#
Pigweed AI summary: This module includes a proto encoder, two different proto decoders, codegen for direct wire-format encoders/decoders, and a table-based codegen system for constructing proto messages as in-memory structs. The different encoder/decoder costs are as follows: - Full wire-format proto encode/decode library: +6,720 FLASH - Including table-based Message encoder and decoder: +9,170 FLASH. There is some overhead involved in ensuring all of the encoder/decoder functionality is pulled
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:
| Label | Segment | Delta | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Full wire-format proto encode/decode library | 
FLASH
 | +6,720 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Including table-based Message encoder and decoder | 
FLASH
 | +9,170 | 
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#
Pigweed AI summary: This paragraph summarizes a size report for encoding/decoding the "pw.protobuf.test.ItemInfo" message. The message is described as trivial with just a few integers. The report includes measurements for different encoding/decoding methods, such as direct wire-format proto encoder, generated wrapped wire-format encoder, and generated message encoder. The measurements include the size increase in terms of flash and RAM memory.
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.
| Label | Segment | Delta | |||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Direct wire-format proto encoder | 
FLASH
 | +200 | |||||||||||||||||||||
| 
RAM
 | +104 | ||||||||||||||||||||||
| Generated wrapped wire-format encoder | 
FLASH
 | +290 | |||||||||||||||||||||
| 
RAM
 | +148 | ||||||||||||||||||||||
| Generated message encoder | 
FLASH
 | +238 | |||||||||||||||||||||
| 
RAM
 | +168 | 
Optional and oneof#
Pigweed AI summary: This paragraph summarizes the size report for encoding/decoding the "pw.protobuf.test.ResponseInfo" message. The message is slightly more complex and includes optional fields, a oneof, and a submessage. The report provides information on the size changes for different encoding methods, including the direct wire-format proto encoder, the generated wrapped wire-format encoder, and the generated message encoder. It includes details on the size changes in terms of flash and RAM memory.
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.
| Label | Segment | Delta | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Direct wire-format proto encoder | 
FLASH
 | +636 | ||||||||||||||||||||||||||||||
| 
RAM
 | +104 | |||||||||||||||||||||||||||||||
| Generated wrapped wire-format encoder | 
FLASH
 | +1,134 | ||||||||||||||||||||||||||||||
| 
RAM
 | +208 | |||||||||||||||||||||||||||||||
| Generated message encoder | 
FLASH
 | +554 | ||||||||||||||||||||||||||||||
| 
RAM
 | +264 |