summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2023-04-01 09:19:35 -0700
committerJeremy Evans <code@jeremyevans.net>2023-04-25 08:06:16 -0700
commitaf2da6419aba1e242e851664b4e6816aeb27f8cb (patch)
tree6c9a085aa6ad05f1134a0c52fd6e58f5c3bf39fd /benchmark
parentf6254f77f7a7c4d1f11180b3b382680868bd9ee4 (diff)
downloadruby-af2da6419aba1e242e851664b4e6816aeb27f8cb.tar.gz
Optimize cfunc calls for f(*a) and f(*a, **kw) if kw is empty
This optimizes the following calls: * ~10-15% for f(*a) when a does not end with a flagged keywords hash * ~10-15% for f(*a) when a ends with an empty flagged keywords hash * ~35-40% for f(*a, **kw) if kw is empty This still copies the array contents to the VM stack, but avoids some overhead. It would be faster to use the array pointer directly, but that could cause problems if the array was modified during the call to the function. You could do that optimization for frozen arrays, but as splatting frozen arrays is uncommon, and the speedup is minimal (<5%), it doesn't seem worth it. The vm_send_cfunc benchmark has been updated to test additional cfunc call types, and the numbers above were taken from the benchmark results.
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/vm_send_cfunc.yml15
1 files changed, 13 insertions, 2 deletions
diff --git a/benchmark/vm_send_cfunc.yml b/benchmark/vm_send_cfunc.yml
index b114ac317d..6f12b65176 100644
--- a/benchmark/vm_send_cfunc.yml
+++ b/benchmark/vm_send_cfunc.yml
@@ -1,3 +1,14 @@
+prelude: |
+ ary = []
+ kw = {a: 1}
+ empty_kw = {}
+ kw_ary = [Hash.ruby2_keywords_hash(a: 1)]
+ empty_kw_ary = [Hash.ruby2_keywords_hash({})]
benchmark:
- vm_send_cfunc: self.class
-loop_count: 100000000
+ vm_send_cfunc: itself
+ vm_send_cfunc_splat: itself(*ary)
+ vm_send_cfunc_splat_kw_hash: equal?(*kw_ary)
+ vm_send_cfunc_splat_empty_kw_hash: itself(*empty_kw_ary)
+ vm_send_cfunc_splat_kw: equal?(*ary, **kw)
+ vm_send_cfunc_splat_empty_kw: itself(*ary, **empty_kw)
+loop_count: 20000000