Protocol Buffers varint vs fixed
This article is much more a note to myself than something else but this might be interesting for people out there.
I wanted to calculate the thresholds at which it is better it is to use a
fixed rather than a varint. Now, knowing that the varint are encoded in base 128, this basically means that we are dealing with power of 128. This gives us the following table:
|Threshold value||Bytes size (without tag)|
- From 268,435,456 to whatever limit you 32 bits type has, it is better to use a
- From 72,057,594,037,927,936 to whatever limit you 64 bits type has, it is better to use a
Written on October 2, 2022