Re: Tidy fill hstv array (src/backend/access/heap/pruneheap.c)

From: Andres Freund <andres(at)anarazel(dot)de>
To: Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>
Cc: "Andrey M(dot) Borodin" <x4mmm(at)yandex-team(dot)ru>, John Naylor <johncnaylorls(at)gmail(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Tidy fill hstv array (src/backend/access/heap/pruneheap.c)
Date: 2024-03-04 18:33:55
Message-ID: 20240304183355.4v3asob6ee4qxdkz@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2024-03-04 18:37:39 Re: incremental backup mishandles XLOG_DBASE_CREATE_FILE_COPY
Previous Message Robert Haas 2024-03-04 18:19:45 Re: RFC: Logging plan of the running query