From dc97cc362f08e3a12cc8a17efdca92e770ddf2bc Mon Sep 17 00:00:00 2001 From: Ping Xie Date: Wed, 1 May 2024 10:29:28 -0700 Subject: [PATCH] Reduce memory allocations Signed-off-by: Ping Xie --- src/cluster_legacy.c | 17 ++++------------- src/server.c | 4 ++++ src/server.h | 2 +- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/cluster_legacy.c b/src/cluster_legacy.c index c6ead92662..2947149fec 100644 --- a/src/cluster_legacy.c +++ b/src/cluster_legacy.c @@ -6898,22 +6898,17 @@ void clusterReplicateOpenSlots(void) int argc = 5; robj **argv = zmalloc(sizeof(robj*)*argc); - robj *cmd_obj = createObject(OBJ_STRING, sdsnew("CLUSTER")); - robj *subcmd_obj = createObject(OBJ_STRING, sdsnew("SETSLOT")); - robj *imp_obj = createObject(OBJ_STRING, sdsnew("IMPORTING")); - robj *mig_obj = createObject(OBJ_STRING, sdsnew("MIGRATING")); - - argv[0] = cmd_obj; - argv[1] = subcmd_obj; + argv[0] =shared.cluster; + argv[1] = shared.setslot; for (int i = 0; i < 2; i++) { clusterNode **nodes_ptr = NULL; if (i == 0) { nodes_ptr = server.cluster->importing_slots_from; - argv[3] = imp_obj; + argv[3] = shared.importing; } else { nodes_ptr = server.cluster->migrating_slots_to; - argv[3] = mig_obj; + argv[3] = shared.migrating; } for (int j = 0; j < CLUSTER_SLOTS; j++) { @@ -6930,9 +6925,5 @@ void clusterReplicateOpenSlots(void) } } - decrRefCount(mig_obj); - decrRefCount(imp_obj); - decrRefCount(subcmd_obj); - decrRefCount(cmd_obj); zfree(argv); } diff --git a/src/server.c b/src/server.c index 9333fb202d..6eaba79b0b 100644 --- a/src/server.c +++ b/src/server.c @@ -1999,6 +1999,10 @@ void createSharedObjects(void) { shared.special_asterick = createStringObject("*",1); shared.special_equals = createStringObject("=",1); shared.redacted = makeObjectShared(createStringObject("(redacted)",10)); + shared.cluster = createStringObject("CLUSTER", 7); + shared.setslot = createStringObject("SETSLOT", 7); + shared.importing = createStringObject("IMPORTING", 9); + shared.migrating = createStringObject("MIGRATING", 9); for (j = 0; j < OBJ_SHARED_INTEGERS; j++) { shared.integers[j] = diff --git a/src/server.h b/src/server.h index 6eb5bb09a1..ba2b19f039 100644 --- a/src/server.h +++ b/src/server.h @@ -1333,7 +1333,7 @@ struct sharedObjectsStruct { *time, *pxat, *absttl, *retrycount, *force, *justid, *entriesread, *lastid, *ping, *setid, *keepttl, *load, *createconsumer, *getack, *special_asterick, *special_equals, *default_username, *redacted, - *ssubscribebulk,*sunsubscribebulk, *smessagebulk, + *ssubscribebulk,*sunsubscribebulk, *smessagebulk, *cluster, *setslot, *importing, *migrating, *select[PROTO_SHARED_SELECT_CMDS], *integers[OBJ_SHARED_INTEGERS], *mbulkhdr[OBJ_SHARED_BULKHDR_LEN], /* "*\r\n" */