| From: | Bryan Green <dbryan(dot)green(at)gmail(dot)com> |
|---|---|
| To: | Ranier Vilela <ranier(dot)vf(at)gmail(dot)com> |
| Cc: | Pg Hackers <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Re: Avoid multiple calls to memcpy (src/backend/access/index/genam.c) |
| Date: | 2026-03-09 14:45:56 |
| Message-ID: | CAF+pBj_RS2KErTqQ6ORXjhVzmukG7Ve0wHU1Kq56xjJfFKwVqA@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
I created an example that is a little bit closer to the actual code and
changed the compiler from C++ to C.
It is interesting the optimization that the compiler has chosen for version
1 versus version 2. One calls
memcpy and one doesn't. There is a good chance the inlining of memcpy as
SSE+scalar per iteration
will be faster for syscache scans-- which I believe are usually small (1-4
keys?).
Probably the only reason to do this patch would be if N is normally large
or if this is considered an
improvement in code clarity without a detrimental impact on small N
syscache scans.
I realize you only said "possible small optimization". It might be
worthwhile to benchmark the code for
different values of n to determine if there is a tipping point either way?
https://godbolt.org/z/dM18cGfE6
-- bg
On Mon, Mar 9, 2026 at 8:05 AM Ranier Vilela <ranier(dot)vf(at)gmail(dot)com> wrote:
>
> Em seg., 9 de mar. de 2026 às 10:16, Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>
> escreveu:
>
>> Hi.
>>
>> In the functions *systable_beginscan* and *systable_beginscan_ordered*,
>> is possible a small optimization.
>> The array *idxkey* can be constructed in one go with a single call to
>> mempcy.
>> The excess might not make much of a difference, but I think it's worth
>> the effort.
>>
>> patch attached.
>>
> Someone asked me if O2 does not do the work.
> Apparently not.
>
> https://godbolt.org/z/h5dndz33x
>
> best regards,
> Ranier Vilela
>
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Xuneng Zhou | 2026-03-09 15:02:09 | Re: Refactor recovery conflict signaling a little |
| Previous Message | Anders Åstrand | 2026-03-09 14:35:15 | Re: Refactoring proposal: initialize structures in a consistent way |