public inbox for [email protected]
help / color / mirror / Atom feedFrom: Ranier Vilela <[email protected]>
To: Bryan Green <[email protected]>
Cc: Pg Hackers <[email protected]>
Subject: Re: Avoid multiple calls to memcpy (src/backend/access/index/genam.c)
Date: Thu, 12 Mar 2026 16:27:13 -0300
Message-ID: <CAEudQArY+Kb0EjL1EwdbSecerJ4DsH=ywcBA7_X7eVDrEwdVWQ@mail.gmail.com> (raw)
In-Reply-To: <CAF+pBj87nrr1jGadSRqZrhik+Y9T7V5e7177MOJX6=8KjUgOkA@mail.gmail.com>
References: <CAEudQApbWon+3Eb9x4WW_D-JkSt2mvfx99dXu9VZ4AeCuTh=fw@mail.gmail.com>
<CAEudQApEfvhNT1fEPURzVcQH7G0A1ukh_ugoCGaErV6_dbndCQ@mail.gmail.com>
<CAF+pBj_RS2KErTqQ6ORXjhVzmukG7Ve0wHU1Kq56xjJfFKwVqA@mail.gmail.com>
<CAEudQAptRymgvmd5hQb2mk-Ft89XcSo_xvC74kv4JBA9v=D4Sg@mail.gmail.com>
<CAF+pBj-K2bgNQRc9ih01WFmAWUaQtVbS37jLtYdYh5LOwOkF6A@mail.gmail.com>
<CAEudQApqk6DXWgqSBdHyH7+wSxJuk7D-DwkGODUcGkUWpYu0UA@mail.gmail.com>
<CAF+pBj-pAGnTh2un8RGcDqSYuMnwGhXv5_MteB77FNjf-Af=tg@mail.gmail.com>
<CAF+pBj87nrr1jGadSRqZrhik+Y9T7V5e7177MOJX6=8KjUgOkA@mail.gmail.com>
Em qui., 12 de mar. de 2026 às 16:21, Bryan Green <[email protected]>
escreveu:
> I modified your memcpy1.c program to not inline the version functions. I
> changed the memcpy function
> call in version 1, added volatile to keep some DCE opportunities from
> happening and added a range
> of N values to keep the compiler from specializing the code for N = 4.
> Before it did DCE and the test1
> function was just a ret.
>
> The interesting issue is the use of malloc versus the stack. The use of
> malloc will probably track closer
> with PG's use of palloc so I would say in that case this is an
> optimization. It might be fun to compile PG
> with and without the patch (in debug mode) and actually see what gets
> generated for this function.
>
> Here are the results I got using your modified benchmark:
> --- stack allocated ---
> stack n=1 v1(patch): 49721599 ns v2(original): 21477302 ns ratio:
> 2.315 original wins
> stack n=2 v1(patch): 52065462 ns v2(original): 28765199 ns ratio:
> 1.810 original wins
> stack n=3 v1(patch): 58914958 ns v2(original): 39726110 ns ratio:
> 1.483 original wins
> stack n=4 v1(patch): 64585275 ns v2(original): 47046397 ns ratio:
> 1.373 original wins
> stack n=5 v1(patch): 73929844 ns v2(original): 58588698 ns ratio:
> 1.262 original wins
> stack n=6 v1(patch): 95465376 ns v2(original): 67807817 ns ratio:
> 1.408 original wins
> stack n=7 v1(patch): 86910226 ns v2(original): 76999488 ns ratio:
> 1.129 original wins
> stack n=8 v1(patch): 107765417 ns v2(original): 86046016 ns ratio:
> 1.252 original wins
>
> --- malloc allocated ---
> malloc n=1 v1(patch): 133283824 ns v2(original): 141361091 ns ratio:
> 0.943 patch wins
> malloc n=2 v1(patch): 145625895 ns v2(original): 180912711 ns ratio:
> 0.805 patch wins
> malloc n=3 v1(patch): 153975594 ns v2(original): 228459879 ns ratio:
> 0.674 patch wins
> malloc n=4 v1(patch): 154483094 ns v2(original): 248157408 ns ratio:
> 0.623 patch wins
> malloc n=5 v1(patch): 157710598 ns v2(original): 298795018 ns ratio:
> 0.528 patch wins
> malloc n=6 v1(patch): 165196636 ns v2(original): 332940132 ns ratio:
> 0.496 patch wins
> malloc n=7 v1(patch): 169576370 ns v2(original): 358438778 ns ratio:
> 0.473 patch wins
> malloc n=8 v1(patch): 184463815 ns v2(original): 403721513 ns ratio:
> 0.457 patch wins
>
Thanks for your attention and tests.
I think that patch can continue then.
best regards,
Ranier Vilela
view thread (17+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: Avoid multiple calls to memcpy (src/backend/access/index/genam.c)
In-Reply-To: <CAEudQArY+Kb0EjL1EwdbSecerJ4DsH=ywcBA7_X7eVDrEwdVWQ@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox