[PATCH] Reduce the Cost of Allocating Contexts

chromatic chromatic at wgz.org
Mon May 18 04:50:24 UTC 2009


The Parrot_Context allocator in src/gc/register.c tries to be clever.  As 
contexts can contain a variable number of each type of register, the theory 
goes that Parrot_Contexts can have variable sizes.  There's an array of free 
lists of various sizes.  Instead of the malloc()/free() pair for each context 
created and destroyed, the system uses this free list.

Of course, it still uses malloc()/free() to manage the lifecycle of the arrays 
used to *store* the number of each type of register used.  These arrays all 
have four INTVAL members.  For each new context used -- not allocated and 
recycled to the free list, but *used* -- Parrot malloc()s a new four-INTVAL 
array.  For each context recycled to the free list, Parrot free()s that four-
INTVAL array.

This stupid little patch makes the smallest, least invasive change to allocate 
that array used for *every* Parrot_Context as part of the context itself.  It 
halves the cost of creating a context and reduces the cost of recycling a 
context by 2/3.  This is most noticable when calling a lot of PIR functions.

This patch could use some cleanup; getting rid of accesses to this array is 
probably an improvement for encapsulation.  I'm attaching it now instead of 
applying it because it needs testing on other platforms, and it's too close to 
Tuesday's release for my comfort.  The release manager may disagree, which is 
fine.

-- c


-------------- next part --------------
A non-text attachment was scrubbed...
Name: context_no_more_malloc.patch
Type: text/x-patch
Size: 3454 bytes
Desc: not available
URL: <http://lists.parrot.org/pipermail/parrot-dev/attachments/20090517/9f045a6e/attachment-0001.bin>


More information about the parrot-dev mailing list