Re: Tidy fill hstv array (src/backend/access/heap/pruneheap.c) - Mailing list pgsql-hackers

From Andres Freund
Subject Re: Tidy fill hstv array (src/backend/access/heap/pruneheap.c)
Date
Msg-id 20240304183355.4v3asob6ee4qxdkz@alap3.anarazel.de
Whole thread Raw
In response to Re: Tidy fill hstv array (src/backend/access/heap/pruneheap.c)  (Ranier Vilela <ranier.vf@gmail.com>)
List pgsql-hackers
Hi,

On 2024-03-04 08:47:11 -0300, Ranier Vilela wrote:
> Does filling a memory area, one by one, with branches, need strong evidence
> to prove that it is better than filling a memory area, all at once, without
> branches?

That's a bogus comparison:

a) the memset version modifies the whole array, rather than just elements that
   correspond to an item - often there will be far fewer items than the
   maximally possible number

b) the memset version initializes array elements that will be set to an actual
   value

c) switching to memset does not elide any branches, as the branch is still
   needed

And even without those, it'd still not be obviously better to use an
ahead-of-time memset(), as storing lots of values at once is more likely to be
bound by memory bandwidth than interleaving different work.

Andres



pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: RFC: Logging plan of the running query
Next
From: Robert Haas
Date:
Subject: Re: incremental backup mishandles XLOG_DBASE_CREATE_FILE_COPY