1.. _module-pw_protobuf-size_report: 2 3================================ 4pw_protobuf extended size report 5================================ 6.. pigweed-module-subpage:: 7 :name: pw_protobuf 8 9``pw_protobuf`` can impact binary size very differently depending on how it's 10used. A series of examples are provided below to illustrate how much certain 11use cases affect binary size. 12 13-------- 14Overview 15-------- 16This module includes a proto encoder, two different proto decoders (one that 17operates on a ``pw::stream::StreamReader`` and another that operates on an in- 18memory buffer), codegen for direct wire-format encoders/decoders, and a 19table-based codegen system for constructing proto messages as in-memory structs. 20 21Here's a brief overview of the different encoder/decoder costs: 22 23.. include:: size_report/protobuf_overview 24 25.. note:: 26 27 There's some overhead involved in ensuring all of the encoder/decoder 28 functionality is pulled in. Check the per-symbol breakdown for more details. 29 30-------------------------------- 31Encoder/decoder codegen overhead 32-------------------------------- 33The different proto serialization/deserialization codegen methods have different 34overhead. Some have a higher up-front cost, but lower complexity (and therefore 35smaller compiler generated code) at the sites of usage. Others trade lower 36up-front code size cost for more complexity at the proto construction and read 37sites. 38 39This example uses the following proto message to construct a variety of use 40cases to illustrate how code and memory requirements can change depending on 41the complexity of the proto message being encoded/decoded. 42 43.. literalinclude:: pw_protobuf_test_protos/size_report.proto 44 :language: protobuf 45 :lines: 14- 46 47This proto is configured with the following options file: 48 49.. literalinclude:: pw_protobuf_test_protos/size_report.pwpb_options 50 :lines: 14- 51 52Trivial proto 53============= 54This is a size report for encoding/decoding the ``pw.protobuf.test.ItemInfo`` 55message. This is a pretty trivial message with just a few integers. 56 57.. include:: size_report/simple_codegen_size_comparison 58 59Optional and oneof 60================== 61This is a size report for encoding/decoding the 62``pw.protobuf.test.ResponseInfo`` message. This is slightly more complex message 63that has a few explicitly optional fields, a oneof, and a submessage. 64 65.. include:: size_report/oneof_codegen_size_comparison 66