Skip to content

Commit 39a333a

Browse files
committed
Marginal performance hack: remove the loop that used to be needed to
look through a freelist for a chunk of adequate size. For a long time now, all elements of a given freelist have been exactly the same allocated size, so we don't need a loop. Since the loop never iterated more than once, you'd think this wouldn't matter much, but it makes a noticeable savings in a simple test --- perhaps because the compiler isn't optimizing on a mistaken assumption that the loop would repeat. AllocSetAlloc is called often enough that saving even a couple of instructions is worthwhile.
1 parent b1a1ea4 commit 39a333a

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

src/backend/utils/mmgr/aset.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Portions Copyright (c) 1994, Regents of the University of California
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/utils/mmgr/aset.c,v 1.71 2007/01/05 22:19:47 momjian Exp $
14+
* $PostgreSQL: pgsql/src/backend/utils/mmgr/aset.c,v 1.72 2007/04/30 00:12:08 tgl Exp $
1515
*
1616
* NOTE:
1717
* This is a new (Feb. 05, 1999) implementation of the allocation set
@@ -516,7 +516,6 @@ AllocSetAlloc(MemoryContext context, Size size)
516516
AllocSet set = (AllocSet) context;
517517
AllocBlock block;
518518
AllocChunk chunk;
519-
AllocChunk priorfree;
520519
int fidx;
521520
Size chunk_size;
522521
Size blksize;
@@ -578,26 +577,16 @@ AllocSetAlloc(MemoryContext context, Size size)
578577
/*
579578
* Request is small enough to be treated as a chunk. Look in the
580579
* corresponding free list to see if there is a free chunk we could reuse.
581-
*/
582-
fidx = AllocSetFreeIndex(size);
583-
priorfree = NULL;
584-
for (chunk = set->freelist[fidx]; chunk; chunk = (AllocChunk) chunk->aset)
585-
{
586-
if (chunk->size >= size)
587-
break;
588-
priorfree = chunk;
589-
}
590-
591-
/*
592580
* If one is found, remove it from the free list, make it again a member
593581
* of the alloc set and return its data address.
594582
*/
583+
fidx = AllocSetFreeIndex(size);
584+
chunk = set->freelist[fidx];
595585
if (chunk != NULL)
596586
{
597-
if (priorfree == NULL)
598-
set->freelist[fidx] = (AllocChunk) chunk->aset;
599-
else
600-
priorfree->aset = chunk->aset;
587+
Assert(chunk->size >= size);
588+
589+
set->freelist[fidx] = (AllocChunk) chunk->aset;
601590

602591
chunk->aset = (void *) set;
603592

@@ -618,7 +607,7 @@ AllocSetAlloc(MemoryContext context, Size size)
618607
/*
619608
* Choose the actual chunk size to allocate.
620609
*/
621-
chunk_size = 1 << (fidx + ALLOC_MINBITS);
610+
chunk_size = (1 << ALLOC_MINBITS) << fidx;
622611
Assert(chunk_size >= size);
623612

624613
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy