summaryrefslogtreecommitdiff
path: root/src/debug.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/debug.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/debug.c')
-rw-r--r--src/debug.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/src/debug.c b/src/debug.c
index 0a947e564..a0352b5dd 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -373,9 +373,7 @@ void _redisAssertPrintClientInfo(redisClient *c) {
char buf[128];
char *arg;
- if (c->argv[j]->type == REDIS_STRING &&
- c->argv[j]->encoding == REDIS_ENCODING_RAW)
- {
+ if (c->argv[j]->type == REDIS_STRING && sdsEncodedObject(c->argv[j])) {
arg = (char*) c->argv[j]->ptr;
} else {
snprintf(buf,sizeof(buf),"Object type: %d, encoding: %d",
@@ -391,7 +389,7 @@ void redisLogObjectDebugInfo(robj *o) {
redisLog(REDIS_WARNING,"Object type: %d", o->type);
redisLog(REDIS_WARNING,"Object encoding: %d", o->encoding);
redisLog(REDIS_WARNING,"Object refcount: %d", o->refcount);
- if (o->type == REDIS_STRING && o->encoding == REDIS_ENCODING_RAW) {
+ if (o->type == REDIS_STRING && sdsEncodedObject(o)) {
redisLog(REDIS_WARNING,"Object raw string len: %zu", sdslen(o->ptr));
if (sdslen(o->ptr) < 4096) {
sds repr = sdscatrepr(sdsempty(),o->ptr,sdslen(o->ptr));