1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-11 20:28:21 +03:00

Reduce more the number of calls to GetMaxBackends()

Some of the code paths changed by aa64f23 can reduce the number of times
GetMaxBackends() is called.  The performance gain is marginal, but most
of the code changed by this commit already did that.  Hence, let's be
clean and apply the same rule everywhere, for consistency.

Some of the code paths, like in deadlock.c, involve only assertions.
These are left unchanged.

Reviewed-by: Nathan Bossart, Robert Haas
Discussion: https://postgr.es/m/YgMpGZhPOjNfS7er@paquier.xyz
This commit is contained in:
Michael Paquier
2022-02-10 10:27:29 +09:00
parent f0cd9097cf
commit 4567596316
3 changed files with 10 additions and 7 deletions

View File

@ -1633,6 +1633,7 @@ SignalBackends(void)
int32 *pids;
BackendId *ids;
int count;
int max_backends = GetMaxBackends();
/*
* Identify backends that we need to signal. We don't want to send
@ -1642,8 +1643,8 @@ SignalBackends(void)
* XXX in principle these pallocs could fail, which would be bad. Maybe
* preallocate the arrays? They're not that large, though.
*/
pids = (int32 *) palloc(GetMaxBackends() * sizeof(int32));
ids = (BackendId *) palloc(GetMaxBackends() * sizeof(BackendId));
pids = (int32 *) palloc(max_backends * sizeof(int32));
ids = (BackendId *) palloc(max_backends * sizeof(BackendId));
count = 0;
LWLockAcquire(NotifyQueueLock, LW_EXCLUSIVE);