1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-31 17:02:12 +03:00

Up to now, SerializableSnapshot and QuerySnapshot are malloc'ed and

free'd for every transaction or statement, respectively.  This patch
puts these data structures into static memory, thus saving a few CPU
cycles and two malloc calls per transaction or (in isolation level
READ COMMITTED) per query.

Manfred Koizar
This commit is contained in:
Bruce Momjian
2003-06-12 01:42:21 +00:00
parent 752a4dac50
commit acd1536d9f
3 changed files with 30 additions and 33 deletions

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinval.c,v 1.55 2003/05/27 17:49:46 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinval.c,v 1.56 2003/06/12 01:42:19 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -305,9 +305,8 @@ GetOldestXmin(bool allDbs)
*----------
*/
Snapshot
GetSnapshotData(bool serializable)
GetSnapshotData(Snapshot snapshot, bool serializable)
{
Snapshot snapshot = (Snapshot) malloc(sizeof(SnapshotData));
SISeg *segP = shmInvalBuffer;
ProcState *stateP = segP->procState;
TransactionId xmin;
@@ -316,18 +315,29 @@ GetSnapshotData(bool serializable)
int index;
int count = 0;
if (snapshot == NULL)
elog(ERROR, "Memory exhausted in GetSnapshotData");
Assert(snapshot != NULL);
/*
* Allocating space for MaxBackends xids is usually overkill;
* lastBackend would be sufficient. But it seems better to do the
* malloc while not holding the lock, so we can't look at lastBackend.
*
* if (snapshot->xip != NULL)
* no need to free and reallocate xip;
*
* We can reuse the old xip array, because MaxBackends does not change
* at runtime.
*/
snapshot->xip = (TransactionId *)
malloc(MaxBackends * sizeof(TransactionId));
if (snapshot->xip == NULL)
elog(ERROR, "Memory exhausted in GetSnapshotData");
{
/*
* First call for this snapshot
*/
snapshot->xip = (TransactionId *)
malloc(MaxBackends * sizeof(TransactionId));
if (snapshot->xip == NULL)
elog(ERROR, "Memory exhausted in GetSnapshotData");
}
globalxmin = xmin = GetCurrentTransactionId();