At high packet rates, parsing a binary protocol is not just about decoding fields. It is also about deciding who owns the payload—and whether decoding needs to copy it at all.
For a small packet, allocating a Vec<u8> and copying the payload may look harmless. At scale, those operations become part of the hot path. The question is whether we can parse the header, validate the packet, and hand off the payload without creating another allocation.
I built four implementations of the same binary protocol decoder to compare the trade-offs:
A baseline parser that copies the payload into a Vec<u8>
A nom parser that borrows the payload
A manual parser using Bytes
A hybrid parser using nom for the header and Bytes for payload ownership
The goal was not to find a universal winner. It was to understand what each approach buys us—and what it costs.
Benchmark results
I ran the implementations with Criterion on the same packet input.…