summaryrefslogtreecommitdiff
path: root/src/t_string.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2012-06-05 21:50:10 +0200
committerantirez <antirez@gmail.com>2013-07-22 10:31:38 +0200
commit894eba07c8484c0f34b09d54a84e69314c37c427 (patch)
tree245c97d2e0b4b10297fa8d461c64b041ab887e68 /src/t_string.c
parentb9cc90a1192a3ac2edbdac63540f889843f37284 (diff)
downloadredis-894eba07c8484c0f34b09d54a84e69314c37c427.tar.gz
Introduction of a new string encoding: EMBSTR
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.
Diffstat (limited to 'src/t_string.c')
-rw-r--r--src/t_string.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/t_string.c b/src/t_string.c
index cbd069d3c..3645ae7c5 100644
--- a/src/t_string.c
+++ b/src/t_string.c
@@ -217,7 +217,7 @@ void setrangeCommand(redisClient *c) {
/* Create a copy when the object is shared or encoded. */
if (o->refcount != 1 || o->encoding != REDIS_ENCODING_RAW) {
robj *decoded = getDecodedObject(o);
- o = createStringObject(decoded->ptr, sdslen(decoded->ptr));
+ o = createRawStringObject(decoded->ptr, sdslen(decoded->ptr));
decrRefCount(decoded);
dbOverwrite(c->db,c->argv[1],o);
}
@@ -436,7 +436,7 @@ void appendCommand(redisClient *c) {
/* If the object is shared or encoded, we have to make a copy */
if (o->refcount != 1 || o->encoding != REDIS_ENCODING_RAW) {
robj *decoded = getDecodedObject(o);
- o = createStringObject(decoded->ptr, sdslen(decoded->ptr));
+ o = createRawStringObject(decoded->ptr, sdslen(decoded->ptr));
decrRefCount(decoded);
dbOverwrite(c->db,c->argv[1],o);
}