From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andres Freund <andres@anarazel.de>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Tomas Vondra <tomas.vondra@2ndquadrant.com>
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: Rethinking MemoryContext creation
Date: Tue, 12 Dec 2017 16:19:12 -0500
Message-ID: <24452.1513113552@sss.pgh.pa.us> (raw)
In-Reply-To: <20171212200208.bwuvwbdlxtlomwri@alap3.anarazel.de>
References: <2264.1512870796@sss.pgh.pa.us>
<9726.1513009650@sss.pgh.pa.us>
<f49b797a-5c92-156a-e624-897a6045d9cc@2ndquadrant.com>
<12544.1513011559@sss.pgh.pa.us>
<CA+TgmoY6czPPXdE+Y8R+S5e6xxG32rciuDfmkivg1dpB0bJSKw@mail.gmail.com>
<15898.1513013778@sss.pgh.pa.us>
<CA+TgmoZx=248OF_KWp8zDHH+pZjOh3i5MW_r0qo3XF5U19oZjA@mail.gmail.com>
<26282.1513021859@sss.pgh.pa.us>
<18302.1513107058@sss.pgh.pa.us>
<CA+Tgmoby7bcUuXfy76+XxcUQNtq0CjRG8M87gqxMF-8MyU7LbQ@mail.gmail.com>
<20171212200208.bwuvwbdlxtlomwri@alap3.anarazel.de>
Andres Freund <andres@anarazel.de> writes:
> On 2017-12-12 14:50:37 -0500, Robert Haas wrote:
>> It strikes me that a way to optimize these cases even more would be to
>> postpone creating the context until it's actually needed. That might
>> not always be a reasonable plan -- in particular, it occurs to me to
>> think that CurTransactionContext is probably so widely used that
>> changing anything about how it works would probably be really painful
>> -- but it might be possible in some cases.
> That's not generally easy without slowing things down though - e.g. we
> don't want to check for ExprContext's existence before every use, there
> can be billions of usages in a single analytics query. The branches (yea
> yea ;)) would show up as being noticeable.
Yeah. Also, in most of these cases what we're doing with the context
is installing it as CurrentMemoryContext while we execute some random
code that might or might not need to palloc anything. We can't just
set CurrentMemoryContext to null - for one thing, that would leave no
trace of how the context should get set up if it's needed. You could
imagine installing some sort of placeholder, but really that's the
mechanism we've already got, in the case where we just make a context
header and no blocks.
>> Another idea I have is that perhaps we could arrange to reuse contexts
>> instead of destroying them and recreating them.
> I'm a bit doubtful that's going to help, maintaining that list isn't
> going to be free, and the lifetime and number of those contexts aren't
> always going to match up.
Actually, this seems like a really promising idea to me. To the extent
that an empty context has standard parameters, they're all
interchangeable, so you could imagine that AllocSetDelete shoves it
onto a freelist after resetting it, instead of just giving it back to
libc. I'm slightly worried about creating allocation islands that
way, but that problem is probably surmountable, if it's real at all.
However, that seems like a different patch from what I'm working on
here.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: tgl@sss.pgh.pa.us, andres@anarazel.de, robertmhaas@gmail.com, tomas.vondra@2ndquadrant.com
Subject: Re: Rethinking MemoryContext creation
In-Reply-To: <24452.1513113552@sss.pgh.pa.us>
References: <2264.1512870796@sss.pgh.pa.us> <9726.1513009650@sss.pgh.pa.us> <f49b797a-5c92-156a-e624-897a6045d9cc@2ndquadrant.com> <12544.1513011559@sss.pgh.pa.us> <CA+TgmoY6czPPXdE+Y8R+S5e6xxG32rciuDfmkivg1dpB0bJSKw@mail.gmail.com> <15898.1513013778@sss.pgh.pa.us> <CA+TgmoZx=248OF_KWp8zDHH+pZjOh3i5MW_r0qo3XF5U19oZjA@mail.gmail.com> <26282.1513021859@sss.pgh.pa.us> <18302.1513107058@sss.pgh.pa.us> <CA+Tgmoby7bcUuXfy76+XxcUQNtq0CjRG8M87gqxMF-8MyU7LbQ@mail.gmail.com> <20171212200208.bwuvwbdlxtlomwri@alap3.anarazel.de> <24452.1513113552@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox