4 ms·
The latest optimized version of the protobuf parser does a remarkably similar thing: https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobu
by haberman 6y ago
The latest optimized version of the protobuf parser does a remarkably similar thing:
https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/parse_context.h#L71-L106 https://github.com/protocolbuffers/protobuf/blob/master/src/...
Protobufs are full of varints, and we want to perform only one bounds-check per field. So we ensure that the input buffer always has at least 16 bytes available to parse per field. If there are fewer than 16 bytes remaining, we copy these last few bytes of data into a patch buffer and parse from that instead.
- asdfasgasdgasdg 6y agoPossible indication of common ancestry.
- waste_monk 6y agoOr perhaps the software equivalent of https://en.wikipedia.org/wiki/Carcinisation https://en.wikipedia.org/wiki/Carcinisation? If it's a common problem then it would not be unsurprising that similar solutions emerge among wildly different codebases. Like a cross between a design pattern and duct-tape.
- saagarjha 6y agoThis is just how you write code like this. When you have OS/processor guarantees that “going a little over” the length is OK and lets you vectorize, then it’s a good idea to do it.
- scaladev 6y ago(More) permanent link for those reading this a few years later. https://github.com/protocolbuffers/protobuf/blob/5a7a4a52a79ce8fe1657b43fc06157e0bd80ade2/src/google/protobuf/parse_context.h#L71-L106 https://github.com/protocolbuffers/protobuf/blob/5a7a4a52a79...