From: Robert Haas Date: Tue, 29 Apr 2014 19:30:36 +0000 (+0000) Subject: Cache the results of the last sb_find_leaf operation. X-Git-Url: http://waps.l3s.uni-hannover.de/gitweb/?a=commitdiff_plain;h=b7bb20a16175162231734c6e6ea8f1e818c91ccc;p=users%2Frhaas%2Fpostgres.git Cache the results of the last sb_find_leaf operation. If all the memory we're accessing is in the same 4GB segment of the address space, this eliminates calls to sb_find_leaf altogether, a significant savings. But even if we're ranging across more than one segment, this should win in cases that have some degree of access locality. --- diff --git a/src/backend/utils/mmgr/sb_region.c b/src/backend/utils/mmgr/sb_region.c index 47ad11c266..1c5156337d 100644 --- a/src/backend/utils/mmgr/sb_region.c +++ b/src/backend/utils/mmgr/sb_region.c @@ -219,12 +219,24 @@ sb_lookup_region(void *ptr) #if SIZEOF_SIZE_T > 4 { Size highbits = p >> 32; + static Size last_highbits = 0; + static sb_lookup_leaf *last_leaf = NULL; - leaf = sb_find_leaf(highbits, false); + /* Quick test to see if we're in same range as before. */ + if (last_highbits == highbits && last_leaf != NULL) + leaf = last_leaf; + else + { + leaf = sb_find_leaf(highbits, false); - /* No lookup table for this 4GB range? OK, no matching region. */ - if (leaf == NULL) - return NULL; + /* No lookup table for this 4GB range? OK, no matching region. */ + if (leaf == NULL) + return NULL; + + /* Remember results of this lookup for next time. */ + last_highbits = highbits; + last_leaf = leaf; + } } #else leaf = &lookup_root_leaf;