Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eOREE-0001EQ-QQ for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Dec 2017 16:46:54 +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 1eORED-0006sa-G0 for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Dec 2017 16:46:53 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eORED-0006sR-9W for pgsql-hackers@lists.postgresql.org; Mon, 11 Dec 2017 16:46:53 +0000 Received: from mail-wr0-x22f.google.com ([2a00:1450:400c:c0c::22f]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eORE9-0000IW-QM for pgsql-hackers@lists.postgresql.org; Mon, 11 Dec 2017 16:46:52 +0000 Received: by mail-wr0-x22f.google.com with SMTP id z34so18238879wrz.10 for ; Mon, 11 Dec 2017 08:46:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=/7AJLmd3neZyy9tyR3nG+SKDJbbXTfDN41eFEXrXRZY=; b=rCoc8Nhf0+FlqMugmIe0KYghMmi98KRCKa0JBaiXqnpSfzITJZy8nycGrThWIeZ5hs BgYzXJQOOcvCoZ9x+I/mMiV2cUta9XbwHi0iDshCzl2BvGSULXwaA1ZhoB7Qluxk5c9s EKsczgUYHcCBhtmwlUNQB9TxSzuecLDrwco7ahv6Ylt+nPqEm1HycvTFUbwut+A+0+EN RhrInau3kua7wedEMBGO1heXX63In4obR2vScnmYtAq+GxP/719tYi/ihDipZvSNpQwf bnYrQRHrnzj8xmH4YSdWY6kxIpI7VwqAE1B3WexdyfePBACbz0N054n4zr3AQgZJXLof L0hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=/7AJLmd3neZyy9tyR3nG+SKDJbbXTfDN41eFEXrXRZY=; b=ZBO4hxMeboO4+Iy2sKOe4uFNVVjCXwJkM2vX3kvcziF2/OHUsp6RDVJHi1SO+RzfGU F6EV116pnpm5bdHQRqYinb+5ICXN+WsJr+Sge9hbC4hWL7qkfp9oCmq9h66E+zmb1beu rqiPmD46ekcv1MbDRnKXMbqnNacuDWA0yOcqqtrTwh1gLyI0R598zzUTpDom0LBZrue7 YbKTgdzVppfnIl+ATtofYnP7P+7LbtCbBqOnr4t8eGCioYEHwg8x4s7D/m2RAvV7GeC+ 9EXdbMuaU7WwvFC4oNFJlApn2/QVVrktg8MdmB1Goy2VLiqFEa2pPPAiJKD9o7nJMzEy jdHQ== X-Gm-Message-State: AKGB3mL9EwnsS6CEyRVQLDaexqemv1klYlnbolbgirwXoIoXTCHcIgtd WySMDVsHgDAWKjLJYAVz92zgAFmFo6WedBrO378Pu9zC76ntH1qNNxc++RXi79aj937GGR84yEY xRDgaf8GIFoIfZzPoIYh+qOf1aI+ldyyvsC9FRZ8b27RyqFF3mdJXM0sEDd/PfMkpIJlspFySAv lJmMnwWCsXqw2UlkfQ X-Google-Smtp-Source: ACJfBosMLx3h1ger5TZlo9Vz67V+CP2qZAZqUOoUSG04MS6X63n1DfgHAUqKvegiTFdgrcFZ4fy9gQ== X-Received: by 10.223.134.134 with SMTP id 6mr978957wrx.72.1513010806682; Mon, 11 Dec 2017 08:46:46 -0800 (PST) Received: from [10.137.2.19] (ip-78-102-97-226.net.upcbroadband.cz. [78.102.97.226]) by smtp.gmail.com with ESMTPSA id m134sm10051251wmg.6.2017.12.11.08.46.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Dec 2017 08:46:46 -0800 (PST) Subject: Re: Rethinking MemoryContext creation To: Tom Lane , pgsql-hackers@lists.postgresql.org References: <2264.1512870796@sss.pgh.pa.us> <9726.1513009650@sss.pgh.pa.us> From: Tomas Vondra Message-ID: Date: Mon, 11 Dec 2017 17:46:43 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <9726.1513009650@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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