-
Couldn't load subscription status.
- Fork 30
Introduce Ractor benchmarks and harness #375
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
Open
luke-gruber
wants to merge
15
commits into
main
Choose a base branch
from
ractor-harness-luke
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+121,025
−120,215
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
216c9fa
Make most benchmarks Ractor compatible
eightbitraptor d693594
Make 30k_methods benchmark Ractor compatible
luke-gruber 4f52349
Add Ractor microbenchmarks and harness
eightbitraptor ff4ab27
Update harness API to match harness-ractor
eightbitraptor f6f3c3b
Fix issues with require "bundler/setup"
luke-gruber cac1ef2
Add knucleotide benchmark from the benchmark game
eightbitraptor 5482d9d
Add Optcarrot Ractor benchmark
luke-gruber 73e552b
Remove the need to specify the full harness path
luke-gruber 5cab2e6
Implement the ability to use multiple harnesses
luke-gruber b295277
Introduce ractor and ractor-only categories
eightbitraptor f057b26
Run Ractor tests in CI
eightbitraptor e191c14
Update documentation for new Ractor benchmarks
eightbitraptor 47eb94f
Rename YJIT_BENCH_RACTOR* to RUBY_BENCH_RACTOR*
eightbitraptor 2494bdc
Remove unused method
eightbitraptor 776a139
Support Platforms that don't define Ractor.make_shareable
eightbitraptor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| *.csv | ||
| *.dump | ||
| logs* | ||
| benchmarks/*/data/ | ||
|
|
||
| __pycache__ | ||
| /benchmarks/discourse | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| require_relative "../../harness/loader" | ||
|
|
||
| run_benchmark(5) do |num_rs, ractor_args| | ||
| output = File.open("/dev/null", "wb") | ||
| input = File.open("/dev/zero", "rb") | ||
| 100_000.times do | ||
| output.write(input.read(10)) | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| source "https://rubygems.org" | ||
| gem "json", "2.13.2" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| GEM | ||
| remote: https://rubygems.org/ | ||
| specs: | ||
| json (2.13.2) | ||
|
|
||
| PLATFORMS | ||
| arm64-darwin-23 | ||
| ruby | ||
|
|
||
| DEPENDENCIES | ||
| json (= 2.13.2) | ||
|
|
||
| BUNDLED WITH | ||
| 2.7.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| require_relative "../../harness/loader" | ||
|
|
||
| Dir.chdir(__dir__) | ||
| use_gemfile | ||
| require "json" | ||
| puts "json v#{JSON::VERSION}" | ||
|
|
||
| ELEMENTS = 100_000 | ||
| list = ELEMENTS.times.map do | ||
| { | ||
| rand => rand, | ||
| rand => rand, | ||
| rand => rand, | ||
| rand => rand, | ||
| rand => rand, | ||
| rand => rand, | ||
| rand => rand, | ||
| rand => rand, | ||
| rand => rand, | ||
| rand => rand, | ||
| }.to_json | ||
| end | ||
| Ractor.make_shareable(list) | ||
|
|
||
| # Work is divided between ractors | ||
| run_benchmark(5, ractor_args: [list]) do |num_rs, list| | ||
| # num_rs: 1,list: 100_000 | ||
| # num_rs: 2 list: 50_000 | ||
| # num_rs: 4 list: 25_000 | ||
| if num_rs.zero? | ||
| num = list.size | ||
| else | ||
| num = list.size / num_rs | ||
| end | ||
| list.each_with_index do |json, idx| | ||
| break if idx >= num | ||
| JSON.parse(json) | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| source "https://rubygems.org" | ||
| gem "json", "2.13.2" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| GEM | ||
| remote: https://rubygems.org/ | ||
| specs: | ||
| json (2.13.2) | ||
|
|
||
| PLATFORMS | ||
| arm64-darwin-23 | ||
| ruby | ||
|
|
||
| DEPENDENCIES | ||
| json (= 2.13.2) | ||
|
|
||
| BUNDLED WITH | ||
| 2.7.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| require_relative "../../harness/loader" | ||
|
|
||
| Dir.chdir(__dir__) | ||
| use_gemfile | ||
| require "json" | ||
| puts "json v#{JSON::VERSION}" | ||
|
|
||
| ELEMENTS = 300_000 | ||
| list = ELEMENTS.times.map do |i| | ||
| { | ||
| "string #{i}" => "value #{i}", | ||
| "string #{i}" => "value #{i}", | ||
| "string #{i}" => "value #{i}", | ||
| "string #{i}" => "value #{i}", | ||
| "string #{i}" => "value #{i}", | ||
| "string #{i}" => "value #{i}", | ||
| "string #{i}" => "value #{i}", | ||
| "string #{i}" => "value #{i}", | ||
| "string #{i}" => "value #{i}", | ||
| "string #{i}" => "value #{i}", | ||
| "string #{i}" => "value #{i}", | ||
| "string #{i}" => "value #{i}", | ||
| "string #{i}" => "value #{i}", | ||
| "string #{i}" => "value #{i}", | ||
| "string #{i}" => "value #{i}", | ||
| "string #{i}" => "value #{i}", | ||
| "string #{i}" => "value #{i}", | ||
| "string #{i}" => "value #{i}", | ||
| "string #{i}" => "value #{i}", | ||
| "string #{i}" => "value #{i}", | ||
| }.to_json | ||
| end | ||
| Ractor.make_shareable(list) | ||
|
|
||
| # Work is divided between ractors | ||
| run_benchmark(5, ractor_args: [list]) do |num_rs, list| | ||
| # num_rs: 1,list: 100_000 | ||
| # num_rs: 2 list: 50_000 | ||
| # num_rs: 4 list: 25_000 | ||
| if num_rs.zero? | ||
| num = list.size | ||
| else | ||
| num = list.size / num_rs | ||
| end | ||
| list.each_with_index do |json, idx| | ||
| break if idx >= num | ||
| JSON.parse(json) | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # The Computer Language Benchmarks Game | ||
| # https://salsa.debian.org/benchmarksgame-team/benchmarksgame/ | ||
| # | ||
| # k-nucleotide benchmark - Ractor implementation | ||
| # Mirrors the Process.fork version structure as closely as possible | ||
|
|
||
| require_relative "../../harness/loader" | ||
|
|
||
| def frequency(seq, length) | ||
| frequencies = Hash.new(0) | ||
| last_index = seq.length - length | ||
|
|
||
| i = 0 | ||
| while i <= last_index | ||
| frequencies[seq.byteslice(i, length)] += 1 | ||
| i += 1 | ||
| end | ||
|
|
||
| [seq.length - length + 1, frequencies] | ||
| end | ||
|
|
||
| def sort_by_freq(seq, length) | ||
| n, table = frequency(seq, length) | ||
|
|
||
| table.sort { |a, b| | ||
| cmp = b[1] <=> a[1] | ||
| cmp == 0 ? a[0] <=> b[0] : cmp | ||
| }.map! { |seq, count| | ||
| "#{seq} #{'%.3f' % ((count * 100.0) / n)}" | ||
| }.join("\n") << "\n\n" | ||
| end | ||
|
|
||
| def find_seq(seq, s) | ||
| _, table = frequency(seq, s.length) | ||
| "#{table[s] || 0}\t#{s}\n" | ||
| end | ||
|
|
||
| def generate_test_sequence(size) | ||
| alu = "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGGGAGGCCGAGGCGGGCGGATCACCTGAGGTCA" + | ||
| "GGAGTTCGAGACCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAATACAAAAATTAGCCGGGCGTGG" + | ||
| "TGGCGCGCGCCTGTAATCCCAGCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGGAGGCGGAGGTT" + | ||
| "GCAGTGAGCCGAGATCGCGCCACTGCACTCCAGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA" | ||
|
|
||
| sequence = "" | ||
| full_copies = size / alu.length | ||
| remainder = size % alu.length | ||
|
|
||
| full_copies.times { sequence << alu } | ||
| sequence << alu[0, remainder] if remainder > 0 | ||
|
|
||
| sequence.upcase.freeze | ||
| end | ||
|
|
||
| # Make sequence shareable for Ractors | ||
| TEST_SEQUENCE = Ractor.make_shareable(generate_test_sequence(100_000)) | ||
|
|
||
| run_benchmark(5) do |num_ractors, ractor_args| | ||
| freqs = [1, 2] | ||
| nucleos = %w(GGT GGTA GGTATT GGTATTTTAATT GGTATTTTAATTTATAGT) | ||
|
|
||
| # Sequential version - mirrors Process version but without Workers | ||
| results = [] | ||
| freqs.each { |i| results << sort_by_freq(TEST_SEQUENCE, i) } | ||
| nucleos.each { |s| results << find_seq(TEST_SEQUENCE, s) } | ||
| results | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| require_relative '../../harness/loader' | ||
| require_relative "../../benchmarks/optcarrot/lib/optcarrot" | ||
|
|
||
| ROM_PATH = File.expand_path("../../benchmarks/optcarrot/examples/Lan_Master.nes", __dir__).freeze | ||
| # deep freeze all the constants | ||
|
|
||
| # rubocop:disable Lint/ShadowingOuterLocalVariable, Style/Semicolon | ||
| Optcarrot::Config::DEFAULT_OPTIONS.each {|k, v| k.freeze; v.freeze }.freeze | ||
| Optcarrot::Config::OPTIONS.each do |k, v| | ||
| k.freeze | ||
| v.each do |k, v| | ||
| k.freeze | ||
| v.each do |k, v| | ||
| k.freeze | ||
| if v.is_a?(Array) | ||
| v.each {|v| v.freeze } | ||
| end | ||
| v.freeze | ||
| end.freeze | ||
| end.freeze | ||
| end.freeze | ||
| Optcarrot::Driver::DRIVER_DB.each do |k, v| | ||
| k.freeze | ||
| v.each {|k, v| k.freeze; v.freeze }.freeze | ||
| end.freeze | ||
| Optcarrot::Audio::PACK_FORMAT.each {|k, v| k.freeze; v.freeze }.freeze | ||
| Optcarrot::APU::Pulse::WAVE_FORM.each {|a| a.freeze }.freeze | ||
| Optcarrot::APU::Triangle::WAVE_FORM.freeze | ||
| Optcarrot::APU::FRAME_CLOCKS.freeze | ||
| Optcarrot::APU::OSCILLATOR_CLOCKS.each {|a| a.freeze }.freeze | ||
| Optcarrot::APU::LengthCounter::LUT.freeze | ||
| Optcarrot::APU::Noise::LUT.freeze | ||
| Optcarrot::APU::Noise::NEXT_BITS_1.each {|a| a.freeze }.freeze | ||
| Optcarrot::APU::Noise::NEXT_BITS_6.each {|a| a.freeze }.freeze | ||
| Optcarrot::APU::DMC::LUT.freeze | ||
| Optcarrot::PPU::DUMMY_FRAME.freeze | ||
| Optcarrot::PPU::BOOT_FRAME.freeze | ||
| Optcarrot::PPU::SP_PIXEL_POSITIONS.each {|k, v| k.freeze; v.freeze }.freeze | ||
| Optcarrot::PPU::TILE_LUT.each {|a| a.each {|a| a.each {|a| a.freeze }.freeze }.freeze }.freeze | ||
| Optcarrot::PPU::NMT_TABLE.each {|k, v| k.freeze; v.freeze }.freeze | ||
| Optcarrot::CPU::DISPATCH.each {|a| a.freeze }.freeze | ||
| Optcarrot::ROM::MAPPER_DB.freeze | ||
| # rubocop:enable Style/Semicolon | ||
|
|
||
| # rubocop:disable Style/MultilineBlockChain | ||
|
|
||
| run_benchmark(10) do | ||
| nes = Optcarrot::NES.new(["-b", "--no-print-video-checksum", ROM_PATH]) | ||
| 200.times { nes.step } | ||
| end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSON keys are always strings but this benchmark is called "parse float".
If we want floats (and not strings) we should use another structure (like
list = ELEMENTS.times.map { [rand, rand...] }).If we are ok with string keys can we wrap these ourselves to make it clear that we are expecting strings? (
"str #{rand}" => rand...)