0

What are the advantages of varint encoding as used in protobuf? Is it simply that for smallish messages varints waste less space and time than variable size encodings that add sublinear space?

I suppose someone thought about typical or average message sizes when they picked varints for protobuf? Any public comments on the reasoning?

Jeff Burdges
  • 4,204
  • 23
  • 46
  • 1
    I found this talking about varients of varints for example : http://web.stanford.edu/class/cs276/Jeff-Dean-compression-slides.pdf – Jeff Burdges Mar 19 '15 at 20:03
  • What do you mean by "variable size encodings that add sublinear space"? – Kenton Varda Mar 20 '15 at 07:49
  • Does this answer your question? [Why is varint an efficient data representation?](https://stackoverflow.com/questions/24614553/why-is-varint-an-efficient-data-representation) – Peter Cordes May 20 '23 at 23:20
  • Also [How do varints take less space?](https://stackoverflow.com/q/61419435). It's a message size vs. CPU-time tradeoff. I think I read that protobuf changed to not use varint anymore, since networks are faster and the CPU time to encode / decode is significant. (Especially without fancy asm instructions like x86 `pext` / `pdep`.) – Peter Cordes May 20 '23 at 23:20

1 Answers1

0

Varints save space. This is pretty much the only consideration. Imagine how good it would be if your small integers took up only 1 byte instead of 8 every time you sent a gigantic array of integers.

Christian Stewart
  • 15,217
  • 20
  • 82
  • 139