This is a patch against Redis 2.2-rc4 that encodes integer keys into the key
pointer itself. The trick here is that a pointer allocated by malloc() on any
reasonable machine will always be aligned. Therefore, the lowest bit must be 0.
We therefore have 63 (or 31) bits to encode the key itself. For databases where
the key can be represented as an integer, this can amount to a big saving. For
our data set, we Redis requires 30% less memory with the patch (we use 15-digit
keys, where values are small set of other integers).
The code needs polishing and a some fixing…
* Although we run 'make test' and this code passes all of the tests there are
still some issues:
There's a memory leak in setExpire
* Redis uses the same dict* functions for sets, passing an 'robj' instead of an
'sds'. However, as robj under any reasonable circumstance will include a nul
('\0') - e.g. the ref-count will never go over 16 bits, or even 8 – an robj
will be left alone. Needless to say, this is a hack.
We think that separating dict functions working on 'robj' and on sds will help
– at least with 2nd option.
Anyway – we would be glad to see the patch as part of Redis, and would
appreciate your help in fixing it.
Original issue reported on code.google.com by sun...@gmail.com on 17 Feb 2011 at 10:20
Original issue reported on code.google.com by
sun...@gmail.com
on 17 Feb 2011 at 10:20Attachments: