4 ms·
> Probably a historical artifact from when the extra 4-8 bytes required posed a serious overhead. Variable length encodings like varint [1] allows to use 1 byt
by citrin_ru 4y ago
> Probably a historical artifact from when the extra 4-8 bytes required posed a serious overhead.
Variable length encodings like varint [1] allows to use 1 byte for small integers and more for large. Zero terminated string will use less memory for large strings, but the difference between 1 (\0) and 3 bytes (varint length) for a 64k string is negligible.
[1] https://sqlite.org/src4/doc/trunk/www/varint.wiki https://sqlite.org/src4/doc/trunk/www/varint.wiki
- vlovich123 4y agoAccessing a varint length isn’t free. In fact, one of the main performance advantages for capnproto / flat buffers if avoiding varint encoding. It may not matter in all cases, but it would in the ones that absolutely needed to access the length frequently. Probably better to just eat the four bytes and do a small string optimization instead.