News for hackers. Stuff that matters.
Re:Don't Use Protobuf for Telemetry by kentonv on Wednesday December 30, 2020 @05:01PM (#25586681)
> AFAIK the C++ implementation would always allocate on the heap for nested messages

FWIW if you reuse the same message object for multiple parsings, it will re-use the sub-objects as well, thus amortizing away the allocation cost. Parsing the same message into the same object twice should do zero allocations on the second parse. This is the intended way to use Protobuf for small-size messages.

Apparently the C++ implementation has also grown support for arena allocation more recently. (After my time, so I don't know much about it.)

Re:Don't Use Protobuf for Telemetry by tijsvd on Wednesday December 30, 2020 @05:28PM (#25586968)
But then all that must come with bookkeeping, which brings its own cost.

Take a look at an implementation like Prost, for Rust. It's very similar to what I did (10 years ago by now). Everything is just inline, except when messages can be recursive (which should be rare for most protocols).

Re:Don't Use Protobuf for Telemetry by haberman on Wednesday December 30, 2020 @06:22PM (#25587528)
> Everything is just inline, except when messages can be recursive (which should be rare for most protocols).

Many messages are have lots of optional sub-message fields, and set only a few of them in any given message. These messages would be huge if everything is inline (especially if the same thing happens in those sub-messages).

I agree that inlining all sub-messages works great for dense schemas, but it assumes too much about the schema to be a good design for a general-purpose proto library I think. Also maps and repeated fields can never be inline.

Re:Don't Use Protobuf for Telemetry by tijsvd on Wednesday December 30, 2020 @06:36PM (#25587651)
Yes, this comes back to use case.

So it's great that there are different implementations for different use cases. It helps that the wire format is simple and well-documented.

Re:Don't Use Protobuf for Telemetry by kentonv on Wednesday December 30, 2020 @06:15PM (#25587463)
The bookkeeping is not that hard... the pointer is null until it is first allocated, then it remains non-null, while a separate boolean indicates whether the sub-message is actually present in the parent.

The big problem is bloat in memory usage if you parse many differently-shaped messages, requiring the app to implement hacks like only reusing a particular object a certain number of times.

Re:Don't Use Protobuf for Telemetry by a_t48 on Wednesday December 30, 2020 @09:46PM (#25589041)
I wish I had known this a few years ago, I could have saved some allocations. :)