Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6897f0e

Browse filesBrowse files
committed
Optimize memory access in GetRunningTransactionData()
e85662d made GetRunningTransactionData() calculate the oldest running transaction id within the current database. This commit optimized this calculation by performing a cheap transaction id comparison before fetching the process database id, while the latter could cause extra cache misses. Reported-by: Noah Misch Discussion: https://postgr.es/m/20240630231816.bf.nmisch%40google.com
1 parent 6c1af54 commit 6897f0e
Copy full SHA for 6897f0e

File tree

Expand file treeCollapse file tree

1 file changed

+11
-6
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+11
-6
lines changed

‎src/backend/storage/ipc/procarray.c

Copy file name to clipboardExpand all lines: src/backend/storage/ipc/procarray.c
+11-6Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2753,8 +2753,6 @@ GetRunningTransactionData(void)
27532753
*/
27542754
for (index = 0; index < arrayP->numProcs; index++)
27552755
{
2756-
int pgprocno = arrayP->pgprocnos[index];
2757-
PGPROC *proc = &allProcs[pgprocno];
27582756
TransactionId xid;
27592757

27602758
/* Fetch xid just once - see GetNewTransactionId */
@@ -2776,11 +2774,18 @@ GetRunningTransactionData(void)
27762774
oldestRunningXid = xid;
27772775

27782776
/*
2779-
* Also, update the oldest running xid within the current database.
2777+
* Also, update the oldest running xid within the current database. As
2778+
* fetching pgprocno and PGPROC could cause cache misses, we do cheap
2779+
* TransactionId comparison first.
27802780
*/
2781-
if (proc->databaseId == MyDatabaseId &&
2782-
TransactionIdPrecedes(xid, oldestDatabaseRunningXid))
2783-
oldestDatabaseRunningXid = xid;
2781+
if (TransactionIdPrecedes(xid, oldestDatabaseRunningXid))
2782+
{
2783+
int pgprocno = arrayP->pgprocnos[index];
2784+
PGPROC *proc = &allProcs[pgprocno];
2785+
2786+
if (proc->databaseId == MyDatabaseId)
2787+
oldestDatabaseRunningXid = xid;
2788+
}
27842789

27852790
if (ProcGlobal->subxidStates[index].overflowed)
27862791
suboverflowed = true;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.