Skip to content

Commit cdededd

Browse files
eightbitraptorluke-gruberetiennebarrie
committed
Make most benchmarks Ractor compatible
Co-Authored-By: Luke Gruber <[email protected]> Co-Authored-By: Étienne Barrié <[email protected]>
1 parent 79567e8 commit cdededd

File tree

27 files changed

+205
-104
lines changed

27 files changed

+205
-104
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*.csv
44
*.dump
55
logs*
6+
benchmarks/*/data/
67

78
__pycache__
89
/benchmarks/discourse

benchmarks/30k_ifelse.rb

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
require_relative '../harness/loader'
2+
if ENV["YJIT_BENCH_RACTOR_HARNESS"]
3+
eval_recv = Object.new
4+
eval_meth = :instance_eval
5+
else
6+
eval_recv = nil
7+
end
8+
19
def fun_l0_n0(x)
210
if (x < 1)
311
fun_l1_n310(x)
@@ -239998,23 +240006,29 @@ def fun_l29_n999(x)
239998240006
end
239999240007
end
240000240008

240001-
@a = 0
240002-
@b = 0
240003-
@c = 0
240004-
@d = 0
240005-
240006-
@count = 0
240007240009
def inc(x)
240008240010
@count += 1
240009240011
end
240010240012

240011-
@x = 0
240012-
240013-
require_relative '../harness/loader'
240014-
240015240013
INTERNAL_ITRS = Integer(ENV.fetch("INTERNAL_ITRS", 200))
240016240014

240017-
run_benchmark(30) do
240015+
main_obj = ENV["YJIT_BENCH_RACTOR_HARNESS"] ? eval_recv : nil
240016+
run_benchmark(30, ractor_args: [main_obj]) do |num_rs, selv|
240017+
if selv
240018+
recv = selv
240019+
recv_meth = :instance_eval
240020+
else
240021+
recv = 1
240022+
recv_meth = :times
240023+
end
240024+
recv.send(recv_meth) do
240025+
@a = 0
240026+
@b = 0
240027+
@c = 0
240028+
@d = 0
240029+
240030+
@count = 0
240031+
@x = 0
240018240032
INTERNAL_ITRS.times do
240019240033
@x = (@x < 1)? 1:0
240020240034
fun_l0_n0(@x)
@@ -241017,5 +241031,6 @@ def inc(x)
241017241031
fun_l0_n997(@x)
241018241032
fun_l0_n998(@x)
241019241033
fun_l0_n999(@x)
241034+
end
241020241035
end
241021241036
end

benchmarks/attr_accessor.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ def get_value_loop
3434
end
3535
end
3636

37-
obj = TheClass.new
37+
OBJ = TheClass.new
38+
Ractor.make_shareable(OBJ)
3839

39-
run_benchmark(850) do
40-
obj.get_value_loop
40+
run_benchmark(10) do
41+
OBJ.get_value_loop
4142
end

benchmarks/binarytrees/benchmark.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@ def bottom_up_tree(depth)
1616
[bottom_up_tree(depth), bottom_up_tree(depth)]
1717
end
1818

19-
max_depth = 14
20-
min_depth = 4
19+
MAX_DEPTH = 14
20+
MIN_DEPTH = 4
2121

22-
max_depth = min_depth + 2 if min_depth + 2 > max_depth
23-
stretch_depth = max_depth + 1
22+
MAX_DEPTH = MIN_DEPTH + 2 if MIN_DEPTH + 2 > MAX_DEPTH
23+
STRETCH_DEPTH = MAX_DEPTH + 1
2424

2525
require_relative '../../harness/loader'
2626

2727
run_benchmark(60) do
28+
max_depth = MAX_DEPTH
29+
min_depth = MIN_DEPTH
30+
stretch_depth = STRETCH_DEPTH
2831
stretch_tree = bottom_up_tree(stretch_depth)
2932
stretch_tree = nil
3033

benchmarks/blurhash/benchmark.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def [](from, len)
4646
end
4747
end
4848

49-
CHARACTERS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#$%*+,-.:;=?@[]^_{|}~".bytes
49+
CHARACTERS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#$%*+,-.:;=?@[]^_{|}~".bytes.freeze
5050

5151
def self.sRGBToLinear(value)
5252
v = value.to_f / 255
@@ -176,8 +176,8 @@ def blurHashForPixels(xComponents, yComponents, width, height, rgb, bytesPerRow)
176176

177177
FILE = File.join(__dir__, "test.bin")
178178

179-
array = File.read(FILE).bytes
179+
Ractor.make_shareable(ARRAY = File.read(FILE).bytes)
180180

181181
run_benchmark(10) do
182-
Blurhash.encode_rb(204, 204, array)
182+
Blurhash.encode_rb(204, 204, ARRAY)
183183
end

benchmarks/erubi/benchmark.rb

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,26 @@ def check_result_size(result)
4444
source = generate_source(template)
4545

4646
# Create a method with the generated source
47-
eval "# frozen_string_literal: true\ndef run_erb; #{source}; end"
47+
eval <<RUBY
48+
# frozen_string_literal: true
49+
class ErbRenderer
50+
def initialize(values)
51+
@values = values
52+
end
53+
def run_erb
54+
#{source}
55+
end
56+
end
57+
RUBY
4858

4959
# This is taken from actual "gem server" data
50-
@values = JSON.load(File.read "gem_specs.json")
51-
result = run_erb
52-
check_result_size(result)
60+
VALUES = JSON.load(File.read "gem_specs.json")
61+
Ractor.make_shareable(VALUES)
62+
check_result_size(ErbRenderer.new(VALUES).run_erb)
5363

5464
run_benchmark(50) do
5565
250.times do
56-
#result = eval source
57-
result = run_erb
58-
#check_result_size(result)
59-
66+
ErbRenderer.new(VALUES).run_erb
67+
#.then { |result| check_result_size(result) }
6068
end
6169
end

benchmarks/fannkuchredux/benchmark.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ def fannkuch(n)
5454
end
5555

5656
#n = (ARGV[0] || 1).to_i
57-
n = 9 # Benchmarks Game uses n = 12, but it's too slow
57+
N = 9 # Benchmarks Game uses n = 12, but it's too slow
5858

5959
require_relative '../../harness/loader'
6060

6161
run_benchmark(10) do
62-
sum, flips = fannkuch(n)
62+
sum, flips = fannkuch(N)
6363

6464
if sum != 8629
6565
raise RuntimeError, "incorrect sum: #{sum}"

benchmarks/getivar.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ def get_value_loop
3232
end
3333
end
3434

35-
obj = TheClass.new
35+
OBJ = TheClass.new.freeze
3636

3737
run_benchmark(850) do
38-
obj.get_value_loop
38+
OBJ.get_value_loop
3939
end

benchmarks/graphql/benchmark.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,21 @@
55

66
require "graphql"
77

8-
data = File.read "negotiate.gql"
8+
DATA = Ractor.make_shareable(File.read "negotiate.gql")
9+
10+
if ENV["YJIT_BENCH_RACTOR_HARNESS"]
11+
GraphQL.default_parser
12+
Ractor.make_shareable(GraphQL::Tracing::NullTrace)
13+
GraphQL::Language::Lexer.constants.each do |constant|
14+
Ractor.make_shareable(GraphQL::Language::Lexer.const_get(constant))
15+
end
16+
GraphQL::Language::Parser.constants.each do |constant|
17+
Ractor.make_shareable(GraphQL::Language::Parser.const_get(constant))
18+
end
19+
end
920

1021
run_benchmark(10) do
1122
10.times do |i|
12-
GraphQL.parse data
23+
GraphQL.parse DATA
1324
end
1425
end

benchmarks/hexapdf/benchmark.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@
1818

1919
Dir["/tmp/hexapdf-result*.pdf"].each { |file| FileUtils.rm file }
2020

21-
index = 0
21+
if ENV["YJIT_BENCH_RACTOR_HARNESS"]
22+
Ractor.make_shareable(HexaPDF::DefaultDocumentConfiguration)
23+
Ractor.make_shareable(HexaPDF::GlobalConfiguration)
24+
# TODO... still doesn't work
25+
end
26+
27+
iter = 0
28+
2229
run_benchmark(10) do
2330
## TTF benchmark (v. slow)
2431
#HexaPDF::Composer.create(OUT_FILENAME, page_size: [0, 0, WIDTH, HEIGHT], margin: 0) do |pdf|
@@ -28,8 +35,8 @@
2835
#end
2936

3037
# Non-TTF benchmark
31-
index += 1
32-
out_filename = "/tmp/hexapdf-result-#{ "%03d" % index }.pdf"
38+
iter += 1
39+
out_filename = "/tmp/hexapdf-result-#{ "%03d" % iter }.pdf"
3340

3441

3542
composer = HexaPDF::Composer.new(page_size: [0, 0, WIDTH, HEIGHT], margin: 0)

0 commit comments

Comments
 (0)