Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eOQvb-0007rU-Ro for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Dec 2017 16:27:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eOQvb-00007k-9X for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Dec 2017 16:27:39 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eOQva-00007b-W2 for pgsql-hackers@lists.postgresql.org; Mon, 11 Dec 2017 16:27:39 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eOQvT-00007e-Vs for pgsql-hackers@lists.postgresql.org; Mon, 11 Dec 2017 16:27:37 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id vBBGRU1V009727 for ; Mon, 11 Dec 2017 11:27:30 -0500 From: Tom Lane To: pgsql-hackers@lists.postgresql.org Subject: Re: Rethinking MemoryContext creation In-reply-to: <2264.1512870796@sss.pgh.pa.us> References: <2264.1512870796@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Sat, 09 Dec 2017 20:53:16 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <9725.1513009650.1@sss.pgh.pa.us> Date: Mon, 11 Dec 2017 11:27:30 -0500 Message-ID: <9726.1513009650@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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? regards, tom lane