diff options
author | filipe oliveira <filipecosta.90@gmail.com> | 2022-12-05 06:33:53 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-05 08:33:53 +0200 |
commit | 2d80cd7840d4a6ac0305c9192fc6a5de43759570 (patch) | |
tree | c4a9c650ea7fd32c61859010d2e64318af710156 /src/script.c | |
parent | 61c85a2b2081dffaf45eb8c6b7754b8d9a80c60d (diff) | |
download | redis-2d80cd7840d4a6ac0305c9192fc6a5de43759570.tar.gz |
Reintroduce lua argument cache in luaRedisGenericCommand removed in v7.0 (#11541)
This mechanism aims to reduce calls to malloc and free when
preparing the arguments the script sends to redis commands.
This is a mechanism was originally implemented in 48c49c4
and 4f68655, and was removed in #10220 (thinking it's not needed
and that it has no impact), but it now turns out it was wrong, and it
indeed provides some 5% performance improvement.
The implementation is a little bit too simplistic, it assumes consecutive
calls use the same size in the same arg index, but that's arguably
sufficient since it's only aimed at caching very small things.
We could even consider always pre-allocating args to the full
LUA_CMD_OBJCACHE_MAX_LEN (64 bytes) rather than the right size for the argument,
that would increase the chance they'll be able to be re-used.
But in some way this is already happening since we're using
sdsalloc, which in turn uses s_malloc_usable and takes ownership
of the full side of the allocation, so we are padded to the allocator
bucket size.
Co-authored-by: Oran Agra <oran@redislabs.com>
Co-authored-by: sundb <sundbcn@gmail.com>
Diffstat (limited to 'src/script.c')
-rw-r--r-- | src/script.c | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/src/script.c b/src/script.c index 57fa7eeba..2a770fa61 100644 --- a/src/script.c +++ b/src/script.c @@ -513,22 +513,18 @@ static int scriptVerifyAllowStale(client *c, sds *err) { * up to the engine to take and parse. * The err out variable is set only if error occurs and describe the error. * If err is set on reply is written to the run_ctx client. */ -void scriptCall(scriptRunCtx *run_ctx, robj* *argv, int argc, sds *err) { +void scriptCall(scriptRunCtx *run_ctx, sds *err) { client *c = run_ctx->c; /* Setup our fake client for command execution */ - c->argv = argv; - c->argc = argc; c->user = run_ctx->original_client->user; /* Process module hooks */ moduleCallCommandFilters(c); - argv = c->argv; - argc = c->argc; - struct redisCommand *cmd = lookupCommand(argv, argc); + struct redisCommand *cmd = lookupCommand(c->argv, c->argc); c->cmd = c->lastcmd = c->realcmd = cmd; - if (scriptVerifyCommandArity(cmd, argc, err) != C_OK) { + if (scriptVerifyCommandArity(cmd, c->argc, err) != C_OK) { goto error; } |