diff options
author | Michael Paquier <michael@paquier.xyz> | 2022-02-10 10:27:29 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2022-02-10 10:27:29 +0900 |
commit | 4567596316d186c6e61c72df013797266fcac2f7 (patch) | |
tree | b1dba64375bc8b58dc6afd4ec041b19fb6704759 /src/backend/utils/adt/lockfuncs.c | |
parent | f0cd9097cfac435ec18ab2595c81f13a14736758 (diff) |
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
Diffstat (limited to 'src/backend/utils/adt/lockfuncs.c')
-rw-r--r-- | src/backend/utils/adt/lockfuncs.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/backend/utils/adt/lockfuncs.c b/src/backend/utils/adt/lockfuncs.c index 4e517b28e17..944cd6df03f 100644 --- a/src/backend/utils/adt/lockfuncs.c +++ b/src/backend/utils/adt/lockfuncs.c @@ -559,13 +559,14 @@ pg_safe_snapshot_blocking_pids(PG_FUNCTION_ARGS) int *blockers; int num_blockers; Datum *blocker_datums; + int max_backends = GetMaxBackends(); /* A buffer big enough for any possible blocker list without truncation */ - blockers = (int *) palloc(GetMaxBackends() * sizeof(int)); + blockers = (int *) palloc(max_backends * sizeof(int)); /* Collect a snapshot of processes waited for by GetSafeSnapshot */ num_blockers = - GetSafeSnapshotBlockingPids(blocked_pid, blockers, GetMaxBackends()); + GetSafeSnapshotBlockingPids(blocked_pid, blockers, max_backends); /* Convert int array to Datum array */ if (num_blockers > 0) |