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.96) (envelope-from ) id 1vw2Ai-00GaRC-0H for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Feb 2026 18:02:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vw2Ae-005SDN-1o for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Feb 2026 18:02:36 +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.96) (envelope-from ) id 1vw2Ae-005SD5-0v for pgsql-hackers@lists.postgresql.org; Fri, 27 Feb 2026 18:02:36 +0000 Received: from fhigh-a6-smtp.messagingengine.com ([103.168.172.157]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vw2Aa-00000001boC-3Yft for pgsql-hackers@lists.postgresql.org; Fri, 27 Feb 2026 18:02:35 +0000 Received: from phl-compute-10.internal (phl-compute-10.internal [10.202.2.50]) by mailfhigh.phl.internal (Postfix) with ESMTP id E8A9A1400031; Fri, 27 Feb 2026 13:02:30 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-10.internal (MEProxy); Fri, 27 Feb 2026 13:02:30 -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=fm3; t=1772215350; x=1772301750; bh=+GDzg+wh20 Ztyb65y2B90hp6aTAporRJO5Flpmy3zGM=; b=te3l3jLhedr0VnIXV8ZhqxsV7L h3aRtzNRnsvfcCOEdmgOf2s1+hEJTb7xuKNBvAbdTl42y03lBqmR6ViQDT8i9Q+Z RfwOS3bsChbu2upOSHsQmTKp81ddLHETbWrE6eStrwvsVH+CQv26xsQnqau+5a6P n44ffBft8ohH+OgBvNkCauoJnE+AbysDmnrZnnastdpd6zNQsb932m029ha9MBIH ys2x19CHYL5ykqoZ/s8ifwZ9iERQEENZMvpfBcv7wRp20bWA0rNo9n0XIKJJdyQA Y0UjbptpTbHjTNDfaj8BifzE3mXUjH56BAfz4ybbiPot6UQKuNP+6Jt3qmiw== 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-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1772215350; x=1772301750; bh=+GDzg+wh20Ztyb65y2B90hp6aTAporRJO5F lpmy3zGM=; b=WI+vyMlcr9FWLthzsXmU2OkbWKkX+1UZJivhym856bHTfep9wud 7Z/FgCk96jg0US32wHEx1nji7iZCioLsRhXprzH/D3qh2vKornzPR6nGoGoInDyZ qCIh+mm9qHiDRGHnO/JVVAP5kjg5w2el3eUU321t+T92nkeCFvH7u8IQltitYuzI 9qZlhIyuS5c6HHHqFrFiNpY1diKUe85z0htH3NSa1anoSdnRuMTXhq+8iRkN3Cg/ m7JnX8NIhoe1tOWG25nsHeijqOEv8sA5CLDQw6Hbr+4FcaHqH+KJRnEXL/cKH1Y7 g6sIpU8flcdG6n+I8HmvDqznAWLFAVMlocw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvgeelieejucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepfffhvfevuffkfhggtggujgesthdtsfdttddtvdenucfhrhhomheptehnughrvghs ucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrfgrth htvghrnhepfeffgfelvdffgedtveelgfdtgefghfdvkefggeetieevjeekteduleevjefh ueegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprg hnughrvghssegrnhgrrhgriigvlhdruggvpdhnsggprhgtphhtthhopeefpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehthhhomhgrshdrmhhunhhrohesghhmrghilhdrtg homhdprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehlihhsthhsrdhpohhsthhg rhgvshhqlhdrohhrghdprhgtphhtthhopehtghhlsehsshhsrdhpghhhrdhprgdruhhs X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 27 Feb 2026 13:02:30 -0500 (EST) Date: Fri, 27 Feb 2026 13:02:30 -0500 From: Andres Freund To: Tom Lane Cc: Thomas Munro , PostgreSQL Hackers Subject: Re: A stack allocation API Message-ID: References: <854785.1772206539@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <854785.1772206539@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2026-02-27 10:35:39 -0500, Tom Lane wrote: > Thomas Munro writes: > > I also wondered if we might have a reasonable case for using alloca(), > > where available. It's pretty much the thing we are emulating, but > > keeps the stack nice and compact without big holes to step over for > > the following call to strcoll_l() or whatever it might be. > > +1 for investigating alloca(). The one disadvantage I can see > to making this coding pattern more common is that it'll result in > increased stack usage, which is not great now and will become > considerably less great in our hypothetical multithreaded future. Yea, that's what I immediately was thinking about too. IIRC, on linux, the stack for the "main" thread is allocated on-demand, but the stack for threads is mapped entirely upon creation (I think because it'd be hard to ensure there's space for the stack otherwise). So there's more benefit in keeping the stack small-ish with threads than there is in a process based model. That said, I've thought about accellerating a few things with an 'on-stack-if-small-palloc-otherwise' approach as well. Particularly things like small StringInfos could really benefit from it - but it'd be a nontrivial conversion, due code calling pfree on the memory. I guess we could introduce a memory context that'd do nothing for pfree(), which could be used when using the stack version, but IDK, that seems mighty ugly. However, I'm pretty unconvinced of this argument > in the past we've forgotten to pfree() large allocations and had to fix leaks because we'll continue to rely on calling something to free anyway (due to large objects) and using a different path for smaller objects just will make it harder to find those. I wish msvc implemented something akin to gcc/clang's attribute(cleanup(cleanup_function)), but it doesn't look like it does. Obviously it would if we were to compile with C++, but I don't think anybody has appetite for the work it'd need to get there. Greetings, Andres Freund