Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rdHx0-004oh4-8u for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Feb 2024 22:53:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rdHwy-00EYKl-Mu for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Feb 2024 22:53:57 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rdHwx-00EYIZ-3g for pgsql-hackers@lists.postgresql.org; Thu, 22 Feb 2024 22:53:56 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rdHwq-000PFZ-KK for pgsql-hackers@postgresql.org; Thu, 22 Feb 2024 22:53:54 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 5571C5C00C9; Thu, 22 Feb 2024 17:53:45 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 22 Feb 2024 17:53:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1708642425; x=1708728825; bh=nx3bQM+Htc c8O+WLGJ14hVLeIPj1T4P1e38XcDc2pQE=; b=CrChSppWwBk0dbAZhvhiIM7U2g LOdd9ZpOgde4hxO9IY8mEPTZq8QB6oPjihCjo3FIDPLs8a+zrJNQlY8Ht7e1xn8t ozgVoEK1DiivWcFNlykk4Z4X4xSLYJM0bUP42gV3N+zPezSWG0BbDqwR11bcCZe8 +dYWUY5PtJxWR08RBKAge31nKtJpLF8qI75e1XOSVIhfKwulwtgYncDUtZhzO6TK PBVrEVzZa0iKDyHCzpJ4HSOw95tMBNwZtmyiqpI8bz+01b/XSIzHIGZNJ75ARaqn 4bH8ntYzoPM+H3fm5X7sNfHj1emCWFdhVv9AhBaWx0rx8/fV9OnZH0CNWQdQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1708642425; x=1708728825; bh=nx3bQM+Htcc8O+WLGJ14hVLeIPj1 T4P1e38XcDc2pQE=; b=RxYJUtvcx7SfPhKfDDnkLrgVnwXUrJxXvQZjHCHnFAts z/or7UnM7hitoN8U0Bz0Om28B2p+9Dhiyx5RbburusCwy3hIWh8s3AxMQPeQrQAs eKkC1/xEbg0T6G2+3wosSk7kqn5kjzh9h1UH/CuzXhESD7PeYjgNOJVTzNh4ef+f fWvc+DwaHlvRy5K5fbuU3eeaXxDZs/IPdmXcYVPl6CKRy2YyUNCxDthYRQW+nkqs Zjm7F/KFyuM/TmeiPpxUsShc8k+Drbxj2SJdXgI+IofsCE2ejQF9DKdselaYk7hQ dFLZ3D/Jdcww5M9CJzNkrIGpC4RCDvwL1lgwkjZxNw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfeehgddtvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeetnhgurhgv shcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucggtffrrg htthgvrhhnpedvffefvefhteevffegieetfefhtddvffejvefhueetgeeludehteevudei tedtudenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe grnhgurhgvshesrghnrghrrgiivghlrdguvg X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Feb 2024 17:53:44 -0500 (EST) Date: Thu, 22 Feb 2024 14:53:43 -0800 From: Andres Freund To: David Rowley Cc: pgsql-hackers@postgresql.org, Robert Haas , Michael Paquier , Tomas Vondra Subject: Re: Avoid stack frame setup in performance critical routines using tail calls Message-ID: <20240222225343.7a57fiv7quehhlur@awork3.anarazel.de> References: <20210719195950.gavgs6ujzmjfaiig@alap3.anarazel.de> <20230719085236.jltxal2eztqrprfg@awork3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2024-02-23 00:46:26 +1300, David Rowley wrote: > I've rebased the 0001 patch and gone over it again and made a few > additional changes besides what I mentioned in my review. > > On Wed, 9 Aug 2023 at 20:44, David Rowley wrote: > > Here's a review of v2-0001: > > 2. Why do you need to add the NULL check here? > > > > #ifdef USE_VALGRIND > > - if (method != MCTX_ALIGNED_REDIRECT_ID) > > + if (ret != NULL && method != MCTX_ALIGNED_REDIRECT_ID) > > VALGRIND_MEMPOOL_CHANGE(context, pointer, ret, size); > > #endif > > I removed this NULL check as we're calling the realloc function with > no flags, so it shouldn't return NULL as it'll error out from any OOM > errors. That was probably a copy-paste issue... > > 4. It would be good to see some API documentation in the > > MemoryContextMethods struct. This adds a lot of responsibility onto > > the context implementation without any extra documentation to explain > > what, for example, palloc is responsible for and what the alloc > > function needs to do itself. > > I've done that too. > > I also added header comments for MemoryContextAllocationFailure and > MemoryContextSizeFailure and added some comments to explain in places > like palloc() to warn people not to add checks after the 'alloc' call. > > The rebased patch is 0001 and all of my changes are in 0002. I will > rebase your original 0002 patch later. Thanks! > I think 0001 is much more important, as evident by the reported benchmarks > on this thread. I agree that it's good to tackle 0001 first. I don't understand the benchmark point though. Your benchmark seems to suggest that 0002 improves aset performance by *more* than 0001: for 8 byte aset allocs: time master: 8.86 0001: 8.12 0002: 7.02 So 0001 reduces time by 0.92x and 0002 by 0.86x. John's test shows basically no change for 0002 - which is unsurprising, as 0002 changes aset.c, but the test seems to solely exercise slab, as only SlabAlloc() shows up in the profile. As 0002 only touches aset.c it couldn't really have affected that test. > In absence of anyone else looking at this, I think it's ready to go. > If anyone is following along and wants to review or test it, please do > so soon. Makes sense! > @@ -1061,6 +1072,16 @@ MemoryContextAlloc(MemoryContext context, Size size) > > context->isReset = false; > For a moment this made me wonder if we could move the isReset handling into the allocator slow paths as well - it's annoying to write that bit (and thus dirty the cacheline) over and ove. But it'd be somewhat awkward due to pre-allocated blocks. So that'd be a larger change better done separately. Greetings, Andres Freund