|
|
|
|
|
by fainpul
267 days ago
|
|
Maybe this is a thing people commonly have to do, but I have never heard of it and would have wished the article started with an explanation why simply casting the u64 values to a more appropriate type (u16 in this case) is not good enough. 6 of 16 bits would go to waste. It isn't obvious to me why this is considered substantial enough to go through all this trouble. |
|
This is common in fields like bioinformatics, search engine indexing, or implementing other succinct data structures. In these areas, the entire game is about squeezing massive datasets into RAM to avoid slow disk I/O. Wasting 6 out of 16 bits means your memory usage is almost 40% higher than it needs to be. That can be the difference between a server needing 64GB of RAM versus 100GB.
On top of that, as I mentioned in another comment, packing the data more tightly often makes random access faster than a standard Vec, not slower. Better cache locality means the CPU spends less time waiting for data from main memory, and that performance gain often outweighs the tiny cost of the bit-fiddling instructions.