Optimize iteration over PGPROC for fast-path lock searches.
authorFujii Masao
Fri, 14 Mar 2025 13:49:29 +0000 (22:49 +0900)
committerFujii Masao
Fri, 14 Mar 2025 13:49:29 +0000 (22:49 +0900)
commite80171d57c25caf4362a7de17e96195f905386ea
treecaaf9871da2c99d6dfc2e4b6cca03af7f3cc43f7
parenta359d3701991d040bf7b66cfa7052546eb923c38
Optimize iteration over PGPROC for fast-path lock searches.

This commit improves efficiency in FastPathTransferRelationLocks()
and GetLockConflicts(), which iterate over PGPROCs to search for
fast-path locks.

Previously, these functions recalculated the fast-path group during
every loop iteration, even though it remained constant. This update
optimizes the process by calculating the group once and reusing it
throughout the loop.

The functions also now skip empty fast-path groups, avoiding
unnecessary scans of their slots. Additionally, groups belonging to
inactive backends (with pid=0) are always empty, so checking
the group is sufficient to bypass these backends, further enhancing
performance.

Author: Fujii Masao 
Reviewed-by: Heikki Linnakangas
Reviewed-by: Ashutosh Bapat
Discussion: https://postgr.es/m/07d5fd6a-71f1-4ce8-8602-4cc6883f4bd1@oss.nttdata.com
src/backend/storage/lmgr/lock.c