Re: Pre-alloc ListCell's optimization - Mailing list pgsql-hackers

From Stephen Frost
Subject Re: Pre-alloc ListCell's optimization
Date
Msg-id 20110526185743.GO4548@tamriel.snowman.net
Whole thread Raw
In response to Re: Pre-alloc ListCell's optimization  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Pre-alloc ListCell's optimization  (Greg Stark <gsstark@mit.edu>)
Re: Pre-alloc ListCell's optimization  (Greg Stark <gsstark@mit.edu>)
Re: Pre-alloc ListCell's optimization  (Stephen Frost <sfrost@snowman.net>)
List pgsql-hackers
* Tom Lane (tgl@sss.pgh.pa.us) wrote:
> I'm worried that this type of approach would
> bloat the storage required in those cases to a degree that would make
> the patch unattractive.

While I agree that there is some bloat that'll happen with this
approach, we could reduce it by just having a 4-entry cache instead of
an 8-entry cache.  I'm not really sure that saving those 64 bytes per
list is really worth it though.  The cost of allocating the memory
doesn't seem like it changes a lot between those and I don't think it's
terribly common for us to copy lists around (copyList doesn't memcpy()
them).

> ISTM the first thing we'd need to have before
> we could think about this rationally is some measurements about the
> frequencies of different List lengths in a typical workload.

I agree, that'd be a good thing to have.  I'll look into measuring that.

> When Neil redid the List infrastructure a few years ago, there was some
> discussion of special-casing the very first ListCell, and allocating
> just that cell along with the List header.

Well, we do allocate the first cell when we create a list in new_list(),
but it's a seperate palloc() call.  One of the annoying things that I
ran into with this patch is trying to keep track of if something could
be free'd with pfree() or not.  Can't allow pfree() of something inside
the array, etc.  Handling the 1-entry case would likely be pretty
straight-forward, but you need book-keeping as soon as you go to two,
and all that book-keeping feels like overkill for just a 2-entry cache
to me.

I'll try to collect some info on list lengths and whatnot though and get
a feel for just how much this is likely to help.  Of course, if someone
else has time to help with that, I wouldn't complain. :)
Thanks,
    Stephen

pgsql-hackers by date:

Previous
From: "Joshua D. Drake"
Date:
Subject: #PgWest 2011: CFP now open
Next
From: "Kevin Grittner"
Date:
Subject: Re: SSI predicate locking on heap -- tuple or row?