Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit39a333a

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 timenow, all elements of a given freelist have been exactly the sameallocated size, so we don't need a loop. Since the loop never iteratedmore than once, you'd think this wouldn't matter much, but it makes anoticeable savings in a simple test --- perhaps because the compilerisn't optimizing on a mistaken assumption that the loop would repeat.AllocSetAlloc is called often enough that saving even a couple ofinstructions is worthwhile.
1 parentb1a1ea4 commit39a333a

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
AllocSetset= (AllocSet)context;
517517
AllocBlockblock;
518518
AllocChunkchunk;
519-
AllocChunkpriorfree;
520519
intfidx;
521520
Sizechunk_size;
522521
Sizeblksize;
@@ -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)

[8]ページ先頭

©2009-2025 Movatter.jp