Shared reusable client for RM_Call()#8516
Conversation
A single client pointer is added in the server struct. This is initialized by the first RM_Call() and reused for every subsequent RM_Call() except if it's already in use, which means that it's not used for (recursive) module calls to modules. For these, a new "fake" client is created each time.
|
This is a follow-up on #4623, based on the latest comments. Is something more from the resetCommand needed? I suspect these could be needed: |
|
We certainly need I was thinking about making the server struct member a stack (list) so that repeated calls to RM_Call enjoy some re-use, but then a single nested call would still create a new client, so maybe we better look into why these allocations are so expensive instead. |
|
Last commits add all the necessary reset steps. They are no-ops in the normal case. I've compared with what resetCommand and freeClient are doing.
This PR adds the most simple optimization with a single client. I think module-call-module is a corner case already. If it's actually common enough that it needs to be optimized, we could also use small fixed size array of clients (e.g. 3 or 4 clients), where each RM_Call can loop over them to find one which is free to use (it's free if argv == NULL). No need to allocate the list nodes in that case. |
|
I think this is a great improvement as it is. |
A single client pointer is added in the server struct. This is initialized by the first RM_Call() and reused for every subsequent RM_Call() except if it's already in use, which means that it's not used for (recursive) module calls to modules. For these, a new "fake" client is created each time. Other changes: * Avoid allocating a dict iterator in pubsubUnsubscribeAllChannels when not needed
A single client pointer is added in the server struct. This is
initialized by the first RM_Call() and reused for every subsequent
RM_Call() except if it's already in use, which means that it's not
used for (recursive) module calls to modules. For these, a new
"fake" client is created each time.