1+ # frozen_string_literal: true
12require_relative '../harness/harness-common'
23
34Warning [ :experimental ] = false
45ENV [ "YJIT_BENCH_RACTOR_HARNESS" ] = "1"
56
6- RACTORS = [
7+ default_ractors = [
78 0 , # without ractor
89 1 , 2 , 4 , 6 , 8 , 12 , 16 , 32
9- ] . freeze
10+ ]
11+ if rs = ENV [ "YJIT_BENCH_RACTORS" ]
12+ rs = rs . split ( "," ) . map ( &:to_i ) # If you want to include 0, you have to specify
13+ rs = rs . sort . uniq
14+ if rs . any?
15+ ractors = rs
16+ end
17+ end
18+ RACTORS = ( ractors || default_ractors ) . freeze
1019
1120unless Ractor . method_defined? ( :join )
1221 class Ractor
@@ -32,25 +41,23 @@ def run_benchmark(num_itrs_hint, ractor_args: [], &block)
3241 args = if ractor_args . empty?
3342 [ ]
3443 else
35- Ractor . make_shareable ( ractor_args , copy : true )
44+ ractor_deep_dup ( ractor_args )
3645 end
37- block . call *args
46+ block . call *( [ 0 ] + args )
3847 i += 1
3948 end
4049
4150 blk = Ractor . make_shareable ( block )
4251 RACTORS . each do |rs |
4352 num_itrs = 0
4453 while num_itrs < bench_itrs
45- # copy args before we begin measuring the time so it's not included
46- shareable_args = ractor_args . empty? ? [ ] : Ractor . make_shareable ( ractor_args , copy : true )
4754 before = Process . clock_gettime ( Process ::CLOCK_MONOTONIC )
4855 if rs . zero?
49- block . call *shareable_args
56+ block . call *( [ rs ] + ractor_deep_dup ( ractor_args ) )
5057 else
5158 rs_list = [ ]
5259 rs . times do
53- rs_list << Ractor . new ( *shareable_args , &block )
60+ rs_list << Ractor . new ( *( [ rs ] + ractor_args ) , &block )
5461 end
5562 while rs_list . any?
5663 r , _obj = Ractor . select ( *rs_list )
@@ -68,4 +75,22 @@ def run_benchmark(num_itrs_hint, ractor_args: [], &block)
6875 return_results ( [ ] , stats . values . flatten )
6976end
7077
78+ def ractor_deep_dup ( args )
79+ if Array === args
80+ ret = [ ]
81+ args . each do |el |
82+ ret << ractor_deep_dup ( el )
83+ end
84+ ret
85+ elsif Hash === args
86+ ret = { }
87+ args . each do |k , v |
88+ ret [ ractor_deep_dup ( k ) ] = ractor_deep_dup ( v )
89+ end
90+ ret
91+ else
92+ args . dup
93+ end
94+ end
95+
7196Ractor . make_shareable ( self )
0 commit comments