Re: Avoid stack frame setup in performance critical routines using tail calls - Mailing list pgsql-hackers

From John Naylor
Subject Re: Avoid stack frame setup in performance critical routines using tail calls
Date
Msg-id CAFBsxsGdLkfqPdCFzQS-G7Gp6GXT44gT9M=3NYP67Dr3e_gWAA@mail.gmail.com
Whole thread Raw
In response to Re: Avoid stack frame setup in performance critical routines using tail calls  (Andres Freund <andres@anarazel.de>)
List pgsql-hackers

On Wed, Jul 19, 2023 at 3:53 PM Andres Freund <andres@anarazel.de> wrote:
>
> Hi,
>
> David and I were chatting about this patch, in the context of his bump
> allocator patch.  Attached is a rebased version that is also split up into two
> steps, and a bit more polished.

Here is a quick test -- something similar was used to measure the slab improvements last cycle. With radix tree v37 0001-0011 from [1],

create extension bench_radix_tree;
select avg(load_ms) from generate_series(1,100) x(x), lateral (select * from bench_load_random_int(100 * 1000 * (1+x-x))) a;

The backend was pinned and turbo off. Perf runs were separate from timed runs. I included 0002 for completeness.

v37
         avg        
---------------------
 27.0400000000000000

  32.42%  postgres  bench_radix_tree.so  [.] rt_recursive_set
  21.60%  postgres  postgres             [.] SlabAlloc
  11.06%  postgres  [unknown]            [k] 0xffffffff930018f7
  10.49%  postgres  bench_radix_tree.so  [.] rt_extend_down
   7.07%  postgres  postgres             [.] MemoryContextAlloc
   4.83%  postgres  bench_radix_tree.so  [.] rt_node_insert_inner
   2.19%  postgres  bench_radix_tree.so  [.] rt_grow_node_48
   2.16%  postgres  bench_radix_tree.so  [.] rt_set.isra.0
   1.50%  postgres  bench_radix_tree.so  [.] MemoryContextAlloc@plt

v37 + palloc sibling calls
         avg        
---------------------
 26.0700000000000000

v37 + palloc sibling calls + opt aset
         avg        
---------------------
 26.0900000000000000

  33.78%  postgres  bench_radix_tree.so  [.] rt_recursive_set
  23.04%  postgres  postgres             [.] SlabAlloc
  11.43%  postgres  [unknown]            [k] 0xffffffff930018f7
  11.05%  postgres  bench_radix_tree.so  [.] rt_extend_down
   5.52%  postgres  bench_radix_tree.so  [.] rt_node_insert_inner
   2.47%  postgres  bench_radix_tree.so  [.] rt_set.isra.0
   2.30%  postgres  bench_radix_tree.so  [.] rt_grow_node_48
   1.88%  postgres  postgres             [.] MemoryContextAlloc
   1.44%  postgres  bench_radix_tree.so  [.] MemoryContextAlloc@plt

It's nice to see MemoryContextAlloc go down in the profile.

pgsql-hackers by date:

Previous
From: "Hayato Kuroda (Fujitsu)"
Date:
Subject: Suppress generating WAL records during the upgrade
Next
From: Hannu Krosing
Date:
Subject: Re: How to build a new grammer for pg?