Re: Simplify newNode()

2023-12-19 Thread Heikki Linnakangas
On 18/12/2023 16:28, Heikki Linnakangas wrote: I think we have consensus on patch v2. It's simpler and not less performant than what we have now, at least on modern compilers. Barring objections, I'll commit that. Committed that. -- Heikki Linnakangas Neon (https://neon.tech)

Re: Simplify newNode()

2023-12-18 Thread Heikki Linnakangas
On 15/12/2023 00:44, Tom Lane wrote: Good point. Looking closer, modern compilers will actually turn the MemSetLoop() in MemoryContextAllocZeroAligned() into a call to memset() anyway! Funny. That is true for recent versions of gcc, clang, and MSVC. Not here ... Hmm, according to godbolt, the

Re: Simplify newNode()

2023-12-18 Thread John Naylor
On Fri, Dec 15, 2023 at 5:44 AM Tom Lane wrote: > > I did check that the v1 patch successfully inlines newNode() and > reduces it to just a MemoryContextAllocZeroAligned call, so it's > correct that modern compilers do that better than whatever I tested > in 2008. But I wonder what is happening i

Re: Simplify newNode()

2023-12-14 Thread Thomas Munro
On Fri, Dec 15, 2023 at 11:44 AM Tom Lane wrote: > Heikki Linnakangas writes: > > Yeah, +1 on removing all that, including MemoryContextAllocZeroAligned. > > It's not doing any good as it is, as it gets compiled to be identical to > > MemoryContextAllocZero. > > Also not so here. Admittedly, my

Re: Simplify newNode()

2023-12-14 Thread Tom Lane
Heikki Linnakangas writes: > On 14/12/2023 10:32, Peter Eisentraut wrote: >> But if we think that compilers are now smart enough, maybe we can unwind >> this whole stack a bit more? Maybe we don't need MemSetTest() and/or >> palloc0fast() and/or newNode() at all? > Good point. Looking closer, mo

Re: Simplify newNode()

2023-12-14 Thread Heikki Linnakangas
Yngmh6DsLL83XRVdG%2Bt4GnXYxA2G6KOruY1WljU9y/l3rr2yscB2KoAAHAANgXOHyQE5kBeLW2cMwclcCEFpesE0vBRtaCHaQNrHX9CcB66QIrJWg%2BDeG415rOeusi%2BL31svlexs5/F8kZwkggA%3D%3D -- Heikki Linnakangas Neon (https://neon.tech) From 15e93b1b9fdaf19dd55f943ab4f567b5feed2961 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Thu, 14 Dec 2023 14:44:10 +01

Re: Simplify newNode()

2023-12-14 Thread Peter Eisentraut
On 14.12.23 01:48, Heikki Linnakangas wrote: The newNode() macro can be turned into a static inline function, which makes it a lot simpler. See attached. This was not possible when the macro was originally written, as we didn't require compiler to have static inline support, but nowadays we do.

Re: Simplify newNode()

2023-12-13 Thread Junwang Zhao
On Thu, Dec 14, 2023 at 9:34 AM Zhang Mingli wrote: > > Hi, > > LGTM. > > + Assert(size >= sizeof(Node)); /* need the tag, at least */ > + result = (Node *) palloc0fast(size); > + result->type = tag; > > + return result; > +} > > How about moving the comments /* need the tag, at least */ after res

Re: Simplify newNode()

2023-12-13 Thread Zhang Mingli
Hi, LGTM. + Assert(size >= sizeof(Node)); /* need the tag, at least */ + result = (Node *) palloc0fast(size); + result->type = tag; + return result; +} How about moving the comments /* need the tag, at least */ after result->type = tag; by the way? Zhang Mingli www

Simplify newNode()

2023-12-13 Thread Heikki Linnakangas
The newNode() macro can be turned into a static inline function, which makes it a lot simpler. See attached. This was not possible when the macro was originally written, as we didn't require compiler to have static inline support, but nowadays we do. This was last discussed in 2008, see discus