valeriansaliou / sonic

🦔 Fast, lightweight & schema-less search backend. An alternative to Elasticsearch that runs on a few MBs of RAM.
https://crates.io/crates/sonic-server
Mozilla Public License 2.0
20.13k stars 578 forks source link

Use a varint encoding for the IID? #299

Open vlovich opened 2 years ago

vlovich commented 2 years ago

Today it sounds like Sonic uses a fixed-length 32-bit integer for the IID which limits it to 4B objects per bucket. Would it make sense to switch to a varint encoding for the IID? That would let you handle 64-bit IIDs while also achieving a greater space reduction vs 32-bit IIDs.

valeriansaliou commented 2 years ago

That would unfortunately not work 'as-is' based on the current binary data storage model Sonic uses. It relies on predictible offsets, that is, the size of each block of data (IIDs) must be known in advance.

However, variable length IIDs would be a nice idea, both to increase the max. cardinality of IIDs that can be stored and possibly compact 32 bit IIDs even further eg. to 16 bits if the expected max cardinality is less than 4B.

This would however require substantial refactorings so that this can work.