Re: Simplify newNode()
От | Heikki Linnakangas |
---|---|
Тема | Re: Simplify newNode() |
Дата | |
Msg-id | b0e2c1fe-5db6-4bac-9bc8-ce5d574cd2ec@iki.fi обсуждение исходный текст |
Ответ на | Re: Simplify newNode() (Tom Lane <tgl@sss.pgh.pa.us>) |
Ответы |
Re: Simplify newNode()
|
Список | pgsql-hackers |
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 change happened in GCC version 10.1. Starting with gcc 10.1, it is turned into a memset(). On clang, the same change happened in version 3.4.1. 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. I'm not planning to spend more time on this, but there might be some room for further optimization if someone is interested to do the micro-benchmarking. The obvious thing would be to persuade modern compilers to not switch to memset() in MemoryContextAllocZeroAligned (*), making the old macro logic work the same way it used to on old compilers. Also, instead of palloc0, it might be better for newNode() to call palloc followed by memset. That would allow the compiler to partially optimize away the memset. Most callers fill at least some of the fields after calling makeNode(), so the compiler could generate code that clears only the uninitialized fields and padding bytes. (*) or rather, a new function like MemoryContextAllocZeroAligned but without the 'context' argument. We want to keep the savings in the callers from eliminating the extra argument. -- Heikki Linnakangas Neon (https://neon.tech)
В списке pgsql-hackers по дате отправления: