• A
    Introduction of a new string encoding: EMBSTR · 894eba07
    antirez 提交于
    Previously two string encodings were used for string objects:
    
    1) REDIS_ENCODING_RAW: a string object with obj->ptr pointing to an sds
    stirng.
    
    2) REDIS_ENCODING_INT: a string object where the obj->ptr void pointer
    is casted to a long.
    
    This commit introduces a experimental new encoding called
    REDIS_ENCODING_EMBSTR that implements an object represented by an sds
    string that is not modifiable but allocated in the same memory chunk as
    the robj structure itself.
    
    The chunk looks like the following:
    
    +--------------+-----------+------------+--------+----+
    | robj data... | robj->ptr | sds header | string | \0 |
    +--------------+-----+-----+------------+--------+----+
                         |                       ^
                         +-----------------------+
    
    The robj->ptr points to the contiguous sds string data, so the object
    can be manipulated with the same functions used to manipulate plan
    string objects, however we need just on malloc and one free in order to
    allocate or release this kind of objects. Moreover it has better cache
    locality.
    
    This new allocation strategy should benefit both the memory usage and
    the performances. A performance gain between 60 and 70% was observed
    during micro-benchmarks, however there is more work to do to evaluate
    the performance impact and the memory usage behavior.
    894eba07
bitops.c 15.1 KB