From 5ee9513a7104078d9d2f51aecc354ae67f1ba002 Mon Sep 17 00:00:00 2001 From: ko1 Date: Tue, 24 Oct 2017 11:13:49 +0000 Subject: Lazy Proc allocation for block parameters [Feature #14045] * insns.def (getblockparam, setblockparam): add special access instructions for block parameters. getblockparam checks VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM and if it is not set this instruction creates a Proc object from a given blcok and set VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM. setblockparam is similar to setlocal, but set VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM. * compile.c: use get/setblockparm instead get/setlocal instructions. Note that they are used for method local block parameters (def m(&b)), not for block local method parameters (iter{|&b|). * proc.c (get_local_variable_ptr): creates Proc object for Binding#local_variable_get/set. * safe.c (safe_setter): we need to create Proc objects for postponed block parameters when $SAFE is changed. * vm_args.c (args_setup_block_parameter): used only for block local blcok parameters. * vm_args.c (vm_caller_setup_arg_block): if called with VM_CALL_ARGS_BLOCKARG_BLOCKPARAM flag then passed block values should be a block handler. * test/ruby/test_optimization.rb: add tests. * benchmark/bm_vm1_blockparam*: added. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60397 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- benchmark/bm_vm1_blockparam.rb | 9 +++++++++ benchmark/bm_vm1_blockparam_call.rb | 9 +++++++++ benchmark/bm_vm1_blockparam_pass.rb | 13 +++++++++++++ benchmark/bm_vm1_blockparam_yield.rb | 9 +++++++++ 4 files changed, 40 insertions(+) create mode 100755 benchmark/bm_vm1_blockparam.rb create mode 100755 benchmark/bm_vm1_blockparam_call.rb create mode 100755 benchmark/bm_vm1_blockparam_pass.rb create mode 100755 benchmark/bm_vm1_blockparam_yield.rb (limited to 'benchmark') diff --git a/benchmark/bm_vm1_blockparam.rb b/benchmark/bm_vm1_blockparam.rb new file mode 100755 index 0000000000..11680a2e61 --- /dev/null +++ b/benchmark/bm_vm1_blockparam.rb @@ -0,0 +1,9 @@ +def m &b +end + +i = 0 +while i<30_000_000 # while loop 1 + i += 1 + m{} +end + diff --git a/benchmark/bm_vm1_blockparam_call.rb b/benchmark/bm_vm1_blockparam_call.rb new file mode 100755 index 0000000000..f6102a2b5a --- /dev/null +++ b/benchmark/bm_vm1_blockparam_call.rb @@ -0,0 +1,9 @@ +def m &b + b.call +end + +i = 0 +while i<30_000_000 # while loop 1 + i += 1 + m{} +end diff --git a/benchmark/bm_vm1_blockparam_pass.rb b/benchmark/bm_vm1_blockparam_pass.rb new file mode 100755 index 0000000000..10029a257a --- /dev/null +++ b/benchmark/bm_vm1_blockparam_pass.rb @@ -0,0 +1,13 @@ +def bp_yield + yield +end + +def bp_pass &b + bp_yield &b +end + +i = 0 +while i<30_000_000 # while loop 1 + i += 1 + bp_pass{} +end diff --git a/benchmark/bm_vm1_blockparam_yield.rb b/benchmark/bm_vm1_blockparam_yield.rb new file mode 100755 index 0000000000..6dc01ced7c --- /dev/null +++ b/benchmark/bm_vm1_blockparam_yield.rb @@ -0,0 +1,9 @@ +def bp_yield &b + yield +end + +i = 0 +while i<30_000_000 # while loop 1 + i += 1 + bp_yield{} +end -- cgit v1.2.3