diff options
author | Guy Benoish <guy.benoish@redislabs.com> | 2019-02-12 14:21:21 +0100 |
---|---|---|
committer | Guy Benoish <guy.benoish@redislabs.com> | 2019-02-12 14:21:21 +0100 |
commit | bdd9a8002a6fcc93135eb4125da703b87a1959fa (patch) | |
tree | 3efcf98a9a0f1e435b84efe0a88d2bcdaafcb34d /src/object.c | |
parent | a22815b4e9cfaf607378596d1ed715f71d6762c2 (diff) | |
download | redis-bdd9a8002a6fcc93135eb4125da703b87a1959fa.tar.gz |
Trim SDS free space of retained module strings
In some cases processMultibulkBuffer uses sdsMakeRoomFor to
expand the querybuf, but later in some cases it uses that query
buffer as is for an argv element (see "Optimization"), which means
that the sds in argv may have a lot of wasted space, and then in case
modules keep that argv RedisString inside their data structure, this
space waste will remain for long (until restarted from rdb).
Diffstat (limited to 'src/object.c')
-rw-r--r-- | src/object.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/object.c b/src/object.c index ec0bd02ee..42c247b87 100644 --- a/src/object.c +++ b/src/object.c @@ -415,6 +415,17 @@ int isObjectRepresentableAsLongLong(robj *o, long long *llval) { } } +void trimStringObjectIfNeeded(robj *o) { + /* Optimize the SDS string inside the string object to require + * little space, in case there is more than 10% of free space + * at the end of the SDS string. */ + if (o->encoding == OBJ_ENCODING_RAW && + sdsavail(o->ptr) > sdslen(o->ptr)/10) + { + o->ptr = sdsRemoveFreeSpace(o->ptr); + } +} + /* Try to encode a string object in order to save space */ robj *tryObjectEncoding(robj *o) { long value; @@ -484,11 +495,7 @@ robj *tryObjectEncoding(robj *o) { * We do that only for relatively large strings as this branch * is only entered if the length of the string is greater than * OBJ_ENCODING_EMBSTR_SIZE_LIMIT. */ - if (o->encoding == OBJ_ENCODING_RAW && - sdsavail(s) > len/10) - { - o->ptr = sdsRemoveFreeSpace(o->ptr); - } + trimStringObjectIfNeeded(o); /* Return the original object. */ return o; |