improve malloc efficiency: reduce call times of zrealloc (#10533)
* improve malloc efficiency: reduce call times of zrealloc Co-authored-by: Madelyn Olson <madelyneolson@gmail.com>
This commit is contained in:
parent
625bdaf3d1
commit
ee17e7af8d
@ -960,7 +960,6 @@ clusterNode *createClusterNode(char *nodename, int flags) {
|
||||
memset(node->slots,0,sizeof(node->slots));
|
||||
node->slot_info_pairs = NULL;
|
||||
node->slot_info_pairs_count = 0;
|
||||
node->slot_info_pairs_alloc = 0;
|
||||
node->numslots = 0;
|
||||
node->numslaves = 0;
|
||||
node->slaves = NULL;
|
||||
@ -4726,13 +4725,10 @@ void clusterGenNodesSlotsInfo(int filter) {
|
||||
* or end of slot. */
|
||||
if (i == CLUSTER_SLOTS || n != server.cluster->slots[i]) {
|
||||
if (!(n->flags & filter)) {
|
||||
if (n->slot_info_pairs_count+2 > n->slot_info_pairs_alloc) {
|
||||
if (n->slot_info_pairs_alloc == 0)
|
||||
n->slot_info_pairs_alloc = 8;
|
||||
else
|
||||
n->slot_info_pairs_alloc *= 2;
|
||||
n->slot_info_pairs = zrealloc(n->slot_info_pairs, n->slot_info_pairs_alloc * sizeof(uint16_t));
|
||||
if (!n->slot_info_pairs) {
|
||||
n->slot_info_pairs = zmalloc(2 * n->numslots * sizeof(uint16_t));
|
||||
}
|
||||
serverAssert((n->slot_info_pairs_count + 1) < (2 * n->numslots));
|
||||
n->slot_info_pairs[n->slot_info_pairs_count++] = start;
|
||||
n->slot_info_pairs[n->slot_info_pairs_count++] = i-1;
|
||||
}
|
||||
@ -4747,7 +4743,6 @@ void clusterFreeNodesSlotsInfo(clusterNode *n) {
|
||||
zfree(n->slot_info_pairs);
|
||||
n->slot_info_pairs = NULL;
|
||||
n->slot_info_pairs_count = 0;
|
||||
n->slot_info_pairs_alloc = 0;
|
||||
}
|
||||
|
||||
/* Generate a csv-alike representation of the nodes we are aware of,
|
||||
|
@ -120,7 +120,6 @@ typedef struct clusterNode {
|
||||
unsigned char slots[CLUSTER_SLOTS/8]; /* slots handled by this node */
|
||||
uint16_t *slot_info_pairs; /* Slots info represented as (start/end) pair (consecutive index). */
|
||||
int slot_info_pairs_count; /* Used number of slots in slot_info_pairs */
|
||||
int slot_info_pairs_alloc; /* Allocated number of slots in slot_info_pairs */
|
||||
int numslots; /* Number of slots handled by this node */
|
||||
int numslaves; /* Number of slave nodes, if this is a master */
|
||||
struct clusterNode **slaves; /* pointers to slave nodes */
|
||||
|
Loading…
x
Reference in New Issue
Block a user