From: Tomas Vondra <tomas.vondra@2ndquadrant.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-hackers@lists.postgresql.org
Subject: Re: Rethinking MemoryContext creation
Date: Mon, 11 Dec 2017 17:46:43 +0100
Message-ID: <f49b797a-5c92-156a-e624-897a6045d9cc@2ndquadrant.com> (raw)
In-Reply-To: <9726.1513009650@sss.pgh.pa.us>
References: <2264.1512870796@sss.pgh.pa.us>
<9726.1513009650@sss.pgh.pa.us>
On 12/11/2017 05:27 PM, Tom Lane wrote:
> I wrote:
>> While fooling around with a different problem, I got annoyed at how slow
>> MemoryContext creation and deletion is.
>
> Looking at this some more, there's another micro-optimization we could
> make, which is to try to get rid of the strlen+strcpy operations needed
> for the context name. (And yes, I'm seeing those show up in profiles,
> to the tune of a couple percent of total runtime in some examples.)
>
> For a *very* large majority of the callers of AllocSetContextCreate,
> the context name is a simple C string constant, so we could just store
> the pointer to it and save the space and cycles required to copy it.
> This would require providing a separate API for the few callers that are
> actually passing transient strings, but that's easy enough. I envision
> AllocSetContextCreate becoming a wrapper macro for
> "AllocSetContextCreateExtended", which'd take a flag argument specifying
> whether the context name needs to be copied.
>
> However, unless we want to run around and touch all the ~ 150 calls
> with constant arguments, we'd have to set things up so that the default
> behavior for AllocSetContextCreate is to not copy. This risks breaking
> callers in extensions. Not entirely sure if it's worth that --- any
> thoughts?
>
I don't think silently breaking extensions is particularly attractive
option, so I guess we'll have to run around and tweak the ~150 calls.
regards
--
Tomas Vondra http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
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: tomas.vondra@2ndquadrant.com, tgl@sss.pgh.pa.us
Subject: Re: Rethinking MemoryContext creation
In-Reply-To: <f49b797a-5c92-156a-e624-897a6045d9cc@2ndquadrant.com>
References: <2264.1512870796@sss.pgh.pa.us> <9726.1513009650@sss.pgh.pa.us> <f49b797a-5c92-156a-e624-897a6045d9cc@2ndquadrant.com>
* 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