Skip to content

Commit 2cd2227

Browse files
committed
Filter ractor-only benchmarks from pages
Do not publish benchmarks marked ractor_only because the benchmark data pipeline does not run them.
1 parent 93791e3 commit 2cd2227

6 files changed

Lines changed: 56 additions & 18 deletions

File tree

‎helpers/site_helpers.rb‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
require 'yaml'
2+
require_relative '../lib/benchmark_registry'
23

34
module SiteHelpers
45
def github_link(repository)
56
link_to repository, "https://github.com/#{repository}"
67
end
78

9+
def ruby_bench_benchmarks
10+
@ruby_bench_benchmarks ||= BenchmarkRegistry.new.benchmarks
11+
end
12+
813
def rss_entries
914
@rss_entries ||= begin
1015
entries_file = File.expand_path('source/data/rss_entries.yml', app.root)

‎lib/benchmark_registry.rb‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,26 @@ def initialize(path: DEFAULT_PATH)
77
@path = path
88
end
99

10-
def names
11-
return [] unless File.exist?(@path)
10+
def benchmarks
11+
return {} unless File.exist?(@path)
12+
1213
benchmarks = YAML.safe_load_file(@path)
13-
benchmarks.keys.reject { |name| name.to_s.start_with?('ractor/') }
14+
return {} unless benchmarks.is_a?(Hash)
15+
16+
benchmarks.reject { |name, metadata| filtered?(name, metadata) }
1417
rescue StandardError
15-
[]
18+
{}
19+
end
20+
21+
def names
22+
benchmarks.keys
23+
end
24+
25+
private
26+
27+
def filtered?(name, metadata)
28+
metadata = {} unless metadata.respond_to?(:fetch)
29+
30+
name.to_s.start_with?('ractor/') || metadata.fetch('ractor_only', false)
1631
end
1732
end

‎source/benchmarks/ractor.html.haml‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
:ruby
2-
benchmarks = YAML.load_file(File.expand_path('../../ruby-bench/benchmarks.yml', __dir__))
3-
ractor_only = benchmarks.select { |name, meta| name.to_s.start_with?('ractor/') }
4-
ractor_capable = benchmarks.select { |name, meta| meta['ractor'] && !name.to_s.start_with?('ractor/') }
5-
all_ractor_benchmarks = ractor_only.merge(ractor_capable)
2+
benchmarks = ruby_bench_benchmarks
3+
all_ractor_benchmarks = benchmarks.select { |name, meta| meta['ractor'] }
64

75
.benchmark_page
86
.text-center

‎source/benchmarks/ruby-bench.html.haml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
:ruby
2-
benchmarks = YAML.load_file(File.expand_path('../../ruby-bench/benchmarks.yml', __dir__))
2+
benchmarks = ruby_bench_benchmarks
33
category_benchmarks = %w[headline other micro].map do |category|
44
benchmarks.filter_map do |name, benchmark|
55
if benchmark.fetch('category', 'other') == category
@@ -17,7 +17,7 @@
1717

1818
%ul.nav.nav-pills.benchmark_navbar
1919
- category_benchmarks.each do |benchmarks|
20-
- benchmarks.reject{|b, _| b.to_s.include? 'ractor/'}.each_with_index do |benchmark, index|
20+
- benchmarks.each_with_index do |benchmark, index|
2121
%li.nav-item
2222
%a.nav-link.activate-chart{ href: '#', 'data-id': benchmark }= benchmark
2323
%li.nav-item{ style: 'clear: both; float: left; display: block; position: relative;' }

‎source/index.html.haml‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
%th Benchmarks
1111
%tbody
1212
:ruby
13-
benchmarks = YAML.load_file(File.expand_path('../ruby-bench/benchmarks.yml', __dir__))
13+
benchmarks = ruby_bench_benchmarks
1414
category_benchmarks = {
1515
'Headline Benchmarks' => benchmarks.filter_map { |name, benchmark| name if benchmark.fetch('category', 'other') == 'headline' },
1616
'Other Benchmarks' => benchmarks.filter_map { |name, benchmark| name if benchmark.fetch('category', 'other') == 'other' },
@@ -20,7 +20,7 @@
2020
%tr
2121
%td= category
2222
%td.margined-links
23-
- benchmarks.reject{|b, _| b.to_s.include? 'ractor/'}.each do |benchmark|
23+
- benchmarks.each do |benchmark|
2424
= link_to benchmark, "/benchmarks/ruby-bench.html##{benchmark}"
2525

2626
%h2.text-center ruby/ruby
@@ -93,12 +93,8 @@
9393
%th Benchmarks
9494
%tbody
9595
:ruby
96-
benchmarks = YAML.load_file(File.expand_path('../ruby-bench/benchmarks.yml', __dir__))
97-
# Get all ractor benchmarks - both ractor-only and ractor-capable
98-
ractor_only = benchmarks.select { |name, meta| name.to_s.start_with?('ractor/') }
99-
ractor_capable = benchmarks.select { |name, meta| meta['ractor'] && !name.to_s.start_with?('ractor/') }
100-
# Combine all ractor benchmarks into one list
101-
all_ractor_benchmarks = ractor_only.merge(ractor_capable)
96+
benchmarks = ruby_bench_benchmarks
97+
all_ractor_benchmarks = benchmarks.select { |name, meta| meta['ractor'] }
10298
%tr
10399
%td Ractor
104100
%td.margined-links

‎test/benchmark_registry_test.rb‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,30 @@ def test_names_filters_out_ractor_benchmarks
2626
end
2727
end
2828

29+
def test_names_filters_out_ractor_only_benchmarks
30+
with_benchmarks_file({'regular' => {}, 'ractor-only' => {'ractor_only' => true}}) do |path|
31+
registry = BenchmarkRegistry.new(path: path)
32+
33+
result = registry.names
34+
35+
assert_includes result, 'regular'
36+
refute_includes result, 'ractor-only'
37+
end
38+
end
39+
40+
def test_benchmarks_returns_filtered_metadata
41+
with_benchmarks_file({
42+
'regular' => {'category' => 'headline'},
43+
'ractor-only' => {'ractor_only' => true}
44+
}) do |path|
45+
registry = BenchmarkRegistry.new(path: path)
46+
47+
result = registry.benchmarks
48+
49+
assert_equal({'regular' => {'category' => 'headline'}}, result)
50+
end
51+
end
52+
2953
def test_names_returns_empty_array_if_file_missing
3054
registry = BenchmarkRegistry.new(path: '/nonexistent/path.yml')
3155

0 commit comments

Comments
 (0)