On Tue, Nov 29, 2011 at 7:12 AM, Pavan Deolasee <pavan.deola...@gmail.com> wrote: > I think that a good idea. We need a representation that needs minimum > processing to derive the snapshot.
I was looking over the generated code for GetSnapshotData to see if there is any low hanging fruit for micro-optimization. The assembly mostly looks pretty tight, but there are 3 function calls to TransactionIdPrecedes and TransactionIdFollowsOrEquals. All the parameters are known to be normal xids, so there are duplicated checks for that and a lot of movs for the calling convention. I wonder if replacing them with special case macros would be a good idea. In that case the whole check will compile down to one cmp instruction. I'm running a set of benchmarks now on my laptop, but I guess the difference will mostly become noticeable on beefier hardware when ProcArray lock is heavily contended. Attached is a patch, if anyone wishes to give it a go. -- Ants Aasma
diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c index 19ff524..59ff996 100644 --- a/src/backend/storage/ipc/procarray.c +++ b/src/backend/storage/ipc/procarray.c @@ -1324,7 +1324,7 @@ GetSnapshotData(Snapshot snapshot) /* Update globalxmin to be the smallest valid xmin */ xid = pgxact->xmin; /* fetch just once */ if (TransactionIdIsNormal(xid) && - TransactionIdPrecedes(xid, globalxmin)) + TransactionIdPrecedesBothNormal(xid, globalxmin)) globalxmin = xid; /* Fetch xid just once - see GetNewTransactionId */ @@ -1341,11 +1341,11 @@ GetSnapshotData(Snapshot snapshot) */ if (TransactionIdIsNormal(xid)) { - if (TransactionIdFollowsOrEquals(xid, xmax)) + if (TransactionIdFollowsOrEqualsBothNormal(xid, xmax)) continue; if (pgxact != MyPgXact) snapshot->xip[count++] = xid; - if (TransactionIdPrecedes(xid, xmin)) + if (TransactionIdPrecedesBothNormal(xid, xmin)) xmin = xid; } diff --git a/src/include/access/transam.h b/src/include/access/transam.h index c038fd9..31401f9 100644 --- a/src/include/access/transam.h +++ b/src/include/access/transam.h @@ -44,6 +44,9 @@ #define TransactionIdStore(xid, dest) (*(dest) = (xid)) #define StoreInvalidTransactionId(dest) (*(dest) = InvalidTransactionId) +#define TransactionIdPrecedesBothNormal(id1, id2) ((int32) (id1 - id2) < 0) +#define TransactionIdFollowsOrEqualsBothNormal(id1, id2) ((int32) (id1 - id2) >= 0) + /* advance a transaction ID variable, handling wraparound correctly */ #define TransactionIdAdvance(dest) \ do { \
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers