Skip to content

New encoding for string: embedded SDS. #543

antirez opened this Issue Jun 8, 2012 · 1 comment

1 participant

antirez commented Jun 8, 2012

Note: this issue was already implemented in the memopt branch.

Previously two string encodings were used for string objects:

  • REDIS_ENCODING_RAW: a string object with obj->ptr pointing to an sds string.
  • 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

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.

@antirez antirez was assigned Jun 8, 2012
antirez commented Jul 22, 2013

Merged, closing.

@antirez antirez closed this Jul 22, 2013
@JackieXie168 JackieXie168 pushed a commit that referenced this issue Sep 16, 2014
@srh srh Removed postfix operator++ from bucket_iterator_t. Postfix operators …
…are bad. Mitigates part of issue #543.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.