From: Tom Lane Date: Sat, 14 May 2005 20:29:13 +0000 (+0000) Subject: Minor speed hacks in AllocSetReset: avoid clearing the freelist headers X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=671cc146b8ac24b82b210f9626dceb172d950c84;p=users%2Fbernd%2Fpostgres.git Minor speed hacks in AllocSetReset: avoid clearing the freelist headers when the blocks list is empty (there can surely be no freelist items if the context contains no memory), and use MemSetAligned not MemSet to clear the headers (we assume alignof(pointer) >= alignof(int32)). Per discussion with Atsushi Ogawa. He proposes some further hacking that I'm not yet sold on, but these two changes are unconditional wins since there is no case in which they make things slower. --- diff --git a/src/backend/utils/mmgr/aset.c b/src/backend/utils/mmgr/aset.c index df146c1ca4..afbb57af68 100644 --- a/src/backend/utils/mmgr/aset.c +++ b/src/backend/utils/mmgr/aset.c @@ -395,12 +395,17 @@ AllocSetReset(MemoryContext context) AllocSetCheck(context); #endif + /* Nothing to do if context has never contained any data */ + if (block == NULL) + return; + /* Clear chunk freelists */ - MemSet(set->freelist, 0, sizeof(set->freelist)); + MemSetAligned(set->freelist, 0, sizeof(set->freelist)); + /* New blocks list is either empty or just the keeper block */ set->blocks = set->keeper; - while (block != NULL) + do { AllocBlock next = block->next; @@ -427,6 +432,7 @@ AllocSetReset(MemoryContext context) } block = next; } + while (block != NULL); } /* @@ -451,7 +457,7 @@ AllocSetDelete(MemoryContext context) #endif /* Make it look empty, just in case... */ - MemSet(set->freelist, 0, sizeof(set->freelist)); + MemSetAligned(set->freelist, 0, sizeof(set->freelist)); set->blocks = NULL; set->keeper = NULL;