Skip to content

Commit

Permalink
Avoid the sdslen() on shared.crlf given we know its size beforehand. …
Browse files Browse the repository at this point in the history
…Improve ~3-4% of cpu cycles to lrange logic (redis#10987)

* Avoid the sdslen() on shared.crlf given we know its size beforehand
* Removed shared.crlf from sharedObjects
  • Loading branch information
filipecosta90 authored Aug 4, 2022
1 parent f3588fb commit 6686c6d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ void addReplyBigNum(client *c, const char* num, size_t len) {
} else {
addReplyProto(c,"(",1);
addReplyProto(c,num,len);
addReply(c,shared.crlf);
addReplyProto(c,"\r\n",2);
}
}

Expand Down Expand Up @@ -991,21 +991,21 @@ void addReplyBulkLen(client *c, robj *obj) {
void addReplyBulk(client *c, robj *obj) {
addReplyBulkLen(c,obj);
addReply(c,obj);
addReply(c,shared.crlf);
addReplyProto(c,"\r\n",2);
}

/* Add a C buffer as bulk reply */
void addReplyBulkCBuffer(client *c, const void *p, size_t len) {
addReplyLongLongWithPrefix(c,len,'$');
addReplyProto(c,p,len);
addReply(c,shared.crlf);
addReplyProto(c,"\r\n",2);
}

/* Add sds to reply (takes ownership of sds and frees it) */
void addReplyBulkSds(client *c, sds s) {
addReplyLongLongWithPrefix(c,sdslen(s),'$');
addReplySds(c,s);
addReply(c,shared.crlf);
addReplyProto(c,"\r\n",2);
}

/* Set sds to a deferred reply (for symmetry with addReplyBulkSds it also frees the sds) */
Expand Down
1 change: 0 additions & 1 deletion src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -1680,7 +1680,6 @@ void createSharedObjects(void) {
int j;

/* Shared command responses */
shared.crlf = createObject(OBJ_STRING,sdsnew("\r\n"));
shared.ok = createObject(OBJ_STRING,sdsnew("+OK\r\n"));
shared.emptybulk = createObject(OBJ_STRING,sdsnew("$0\r\n\r\n"));
shared.czero = createObject(OBJ_STRING,sdsnew(":0\r\n"));
Expand Down
2 changes: 1 addition & 1 deletion src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ struct sentinelConfig {
};

struct sharedObjectsStruct {
robj *crlf, *ok, *err, *emptybulk, *czero, *cone, *pong, *space,
robj *ok, *err, *emptybulk, *czero, *cone, *pong, *space,
*queued, *null[4], *nullarray[4], *emptymap[4], *emptyset[4],
*emptyarray, *wrongtypeerr, *nokeyerr, *syntaxerr, *sameobjecterr,
*outofrangeerr, *noscripterr, *loadingerr,
Expand Down

0 comments on commit 6686c6d

Please sign in to comment.