Skip to content

Commit

Permalink
changing addReplySds and sdscat to addReplyStatusLength() within luaR…
Browse files Browse the repository at this point in the history
…eplyToRedisReply() (redis#11556)

profiling EVALSHA\ we see that luaReplyToRedisReply takes 8.73% out of the
56.90% of luaCallFunction CPU cycles. 

Using addReplyStatusLength instead of directly composing the protocol to avoid
sdscatprintf and addReplySds ( which imply multiple sdslen calls ).

The new approach drops
luaReplyToRedisReply CPU cycles to 3.77%
  • Loading branch information
filipecosta90 authored and madolson committed Apr 19, 2023
1 parent 5467a18 commit de1c748
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/script_lua.c
Expand Up @@ -653,7 +653,7 @@ static void luaReplyToRedisReply(client *c, client* script_client, lua_State *lu
if (t == LUA_TSTRING) {
sds ok = sdsnew(lua_tostring(lua,-1));
sdsmapchars(ok,"\r\n"," ",2);
addReplySds(c,sdscatprintf(sdsempty(),"+%s\r\n",ok));
addReplyStatusLength(c, ok, sdslen(ok));
sdsfree(ok);
lua_pop(lua,2);
return;
Expand Down
1 change: 1 addition & 0 deletions src/server.h
Expand Up @@ -2507,6 +2507,7 @@ void addReplyBulkCString(client *c, const char *s);
void addReplyBulkCBuffer(client *c, const void *p, size_t len);
void addReplyBulkLongLong(client *c, long long ll);
void addReply(client *c, robj *obj);
void addReplyStatusLength(client *c, const char *s, size_t len);
void addReplySds(client *c, sds s);
void addReplyBulkSds(client *c, sds s);
void setDeferredReplyBulkSds(client *c, void *node, sds s);
Expand Down

0 comments on commit de1c748

Please sign in to comment.