ruby/benchmark/vm_call_send_iseq.yml
Jeremy Evans 9b4bf02aa8 Optimize send calls
Similar to the bmethod optimization, this avoids using
CALLER_ARG_SPLAT if not necessary.  As long as the method argument
can be shifted off, other arguments are passed through as-is.

This optimizes the following types of calls:

* send(meth, arg) ~5%
* send(meth, *args) ~75% for args.length == 200
* send(meth, *args, **kw) ~50% for args.length == 200
* send(meth, **kw) ~25%
* send(meth, kw: 1) ~115%

Note that empty argument splats do get slower with this approach,
by about 20%.  This is probably because iseq argument setup is
slower for empty argument splats than CALLER_SETUP_ARG is. Other
than non-empty argument splats, other argument splats are faster,
with the speedup depending on the number of arguments.

The following types of calls are not optimized:

* send(*args)
* send(*args, **kw)

This is because the you cannot shift the method argument off
without first splatting the arg.
2023-04-25 08:06:16 -07:00

77 lines
1.5 KiB
YAML

prelude: |
def a0; end
def a1(a) a; end
def s(*a) a; end
def b(kw: 1) kw end
def sb(*a, kw: 1) kw end
t0 = 0.times.to_a
t1 = 1.times.to_a
t10 = 10.times.to_a
t200 = 200.times.to_a
a0_t0 = [:a0, *t0]
a1_t1 = [:a1, *t1]
s_t0 = [:s, *t0]
s_t1 = [:s, *t1]
s_t10 = [:s, *t10]
s_t200 = [:s, *t200]
sb_t0 = [:sb, *t0]
sb_t1 = [:sb, *t1]
sb_t10 = [:sb, *t10]
sb_t200 = [:sb, *t200]
kw = {kw: 2}
benchmark:
send_simple_0: |
send(:a0)
send_simple_1: |
send(:a1, 1)
send_simple_0_splat: |
send(:a0, *t0)
send_simple_1_splat: |
send(:a1, *t1)
send_simple_0_splat_comb: |
send(*a0_t0)
send_simple_1_splat_comb: |
send(*a1_t1)
send_no_splat: |
send(:s)
send_0_splat: |
send(:s, *t0)
send_1_splat: |
send(:s, *t1)
send_10_splat: |
send(:s, *t10)
send_200_splat: |
send(:s, *t200)
send_0_splat_comb: |
send(*s_t0)
send_1_splat_comb: |
send(*s_t1)
send_10_splat_comb: |
send(*s_t10)
send_200_splat_comb: |
send(*s_t200)
send_kw: |
send(:b, kw: 1)
send_no_kw: |
send(:b)
send_kw_splat: |
send(:b, **kw)
send_0_splat_kw: |
send(:sb, *t0, **kw)
send_1_splat_kw: |
send(:sb, *t1, **kw)
send_10_splat_kw: |
send(:sb, *t10, **kw)
send_200_splat_kw: |
send(:sb, *t200, **kw)
send_0_splat_comb_kw: |
send(*sb_t0, **kw)
send_1_splat_comb_kw: |
send(*sb_t1, **kw)
send_10_splat_comb_kw: |
send(*sb_t10, **kw)
send_200_splat_comb_kw: |
send(*sb_t200, **kw)
loop_count: 3000000