From 9d336ac398d3a28f6e5e76f1b3b110bab949bcc5 Mon Sep 17 00:00:00 2001 From: uriyage <78144248+uriyage@users.noreply.github.com> Date: Tue, 28 Feb 2023 19:38:58 +0200 Subject: Try to trim strings only when applicable (#11817) As `sdsRemoveFreeSpace` have an impact on performance even if it is a no-op (see details at #11508). Only call the function when there is a possibility that the string contains free space. * For strings coming from the network, it's only if they're bigger than PROTO_MBULK_BIG_ARG * For strings coming from scripts, it's only if they're smaller than LUA_CMD_OBJCACHE_MAX_LEN * For strings coming from modules, it could be anything. Co-authored-by: Oran Agra Co-authored-by: sundb --- src/server.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/server.h') diff --git a/src/server.h b/src/server.h index 7d8e65b36..36cd8c760 100644 --- a/src/server.h +++ b/src/server.h @@ -2709,7 +2709,7 @@ int compareStringObjects(const robj *a, const robj *b); int collateStringObjects(const robj *a, const robj *b); int equalStringObjects(robj *a, robj *b); unsigned long long estimateObjectIdleTime(robj *o); -void trimStringObjectIfNeeded(robj *o); +void trimStringObjectIfNeeded(robj *o, int trim_small_values); #define sdsEncodedObject(objptr) (objptr->encoding == OBJ_ENCODING_RAW || objptr->encoding == OBJ_ENCODING_EMBSTR) /* Synchronous I/O with timeout */ @@ -3279,6 +3279,9 @@ typedef struct luaScript { uint64_t flags; robj *body; } luaScript; +/* Cache of recently used small arguments to avoid malloc calls. */ +#define LUA_CMD_OBJCACHE_SIZE 32 +#define LUA_CMD_OBJCACHE_MAX_LEN 64 /* Blocked clients API */ void processUnblockedClients(void); -- cgit v1.2.1