Skip to content

vm_call_single_noarg_inline_builtin #7486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 23, 2023

Conversation

ko1
Copy link
Contributor

@ko1 ko1 commented Mar 9, 2023

If the iseq only contains `opt_invokebuiltin_delegate_leave` insn and
the builtin-function (bf) is inline-able, the caller doesn't need to
build a method frame.

`vm_call_single_noarg_inline_builtin` is fast path for such cases.

@ko1
Copy link
Contributor Author

ko1 commented Mar 9, 2023

require 'benchmark'
N = 5_000_000

ary = [1, 2, 3]

Benchmark.bm(10){|x|
  x.report('first'){
    N.times{
      ary.first; ary.first; ary.first; ary.first; ary.first; 
      ary.first; ary.first; ary.first; ary.first; ary.first; 
      ary.first; ary.first; ary.first; ary.first; ary.first; 
      ary.first; ary.first; ary.first; ary.first; ary.first; 
      ary.first; ary.first; ary.first; ary.first; ary.first; 
    }
  }
  x.report('[0]'){
    N.times{
      ary[0]; ary[0]; ary[0]; ary[0]; ary[0]; 
      ary[0]; ary[0]; ary[0]; ary[0]; ary[0]; 
      ary[0]; ary[0]; ary[0]; ary[0]; ary[0]; 
      ary[0]; ary[0]; ary[0]; ary[0]; ary[0]; 
      ary[0]; ary[0]; ary[0]; ary[0]; ary[0]; 
    }
  }
  x.report('last'){
    N.times{
      ary.last; ary.last; ary.last; ary.last; ary.last; 
      ary.last; ary.last; ary.last; ary.last; ary.last; 
      ary.last; ary.last; ary.last; ary.last; ary.last; 
      ary.last; ary.last; ary.last; ary.last; ary.last; 
      ary.last; ary.last; ary.last; ary.last; ary.last; 
    }
  }
  x.report('[-1]'){
    N.times{
      ary[-1]; ary[-1]; ary[-1]; ary[-1]; ary[-1]; 
      ary[-1]; ary[-1]; ary[-1]; ary[-1]; ary[-1]; 
      ary[-1]; ary[-1]; ary[-1]; ary[-1]; ary[-1]; 
      ary[-1]; ary[-1]; ary[-1]; ary[-1]; ary[-1]; 
      ary[-1]; ary[-1]; ary[-1]; ary[-1]; ary[-1]; 
    }
  }
}
master:
                 user     system      total        real
first        2.601405   0.000000   2.601405 (  2.601454)
[0]          1.258742   0.000000   1.258742 (  1.258762)
last         2.550123   0.000000   2.550123 (  2.550144)
[-1]         1.336734   0.000000   1.336734 (  1.336758)

master/yjit:
                 user     system      total        real
first        0.885496   0.007784   0.893280 (  0.893306)
[0]          0.691625   0.000040   0.691665 (  0.691677)
last         0.920018   0.000002   0.920020 (  0.920038)
[-1]         0.754329   0.000027   0.754356 (  0.754458)

modified:
                 user     system      total        real
first        1.447259   0.000854   1.448113 (  1.448137)
[0]          1.227989   0.000042   1.228031 (  1.228081)
last         1.407864   0.000000   1.407864 (  1.407900)
[-1]         1.238353   0.000000   1.238353 (  1.238378)

modified/yjit:
                 user     system      total        real
first        1.118261   0.000000   1.118261 (  1.118273)
[0]          0.669988   0.000000   0.669988 (  0.670006)
last         1.371392   0.000000   1.371392 (  1.371406)
[-1]         0.793146   0.000000   0.793146 (  0.793173)

maybe yjit now does not support Primitive.mandatory_only?.

@ko1 ko1 force-pushed the vm_call_single_noarg_inline_builtin branch 2 times, most recently from 79d784f to 8889c9e Compare March 9, 2023 17:10
@ko1 ko1 force-pushed the vm_call_single_noarg_inline_builtin branch 8 times, most recently from bd686c3 to 0375339 Compare March 22, 2023 18:37
`builtin_inline_index` is restored because THEN clause on
`Primitive.mandatory_only?` was compiled twice.

However, f29c9d6 skips to compile THEN clause so we don't
need to restore `builtin_inline_index`.
@ko1 ko1 force-pushed the vm_call_single_noarg_inline_builtin branch from 0375339 to fb1aad3 Compare March 22, 2023 22:40
ko1 added 2 commits March 23, 2023 11:30
If the iseq only contains `opt_invokebuiltin_delegate_leave` insn and
the builtin-function (bf) is inline-able, the caller doesn't need to
build a method frame.

`vm_call_single_noarg_inline_builtin` is fast path for such cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant