Skip to content

Commit 2e65fd1

Browse files
committed
Step 2: Stop benchmarks crashing on Rubies that lack a feature
Crashes seen in CI, now fixed: - dig-vs-[]-vs-fetch.rb on 2.1 and 2.2: skip only the Hash#dig report (Ruby 2.3+), the other five still run. - slice-native-vs-before-native.rb on 2.1 to 2.4 and JRuby 9.1: skip only the native Hash#slice report (Ruby 2.5+), so the pre-native versions the file is about still run there. - remove-extra-spaces-or-other-chars.rb on 2.1 and 2.2: <<~ (Ruby 2.3+) made the file fail to parse. A plain heredoc builds the same string (checked byte for byte). - bsearch-vs-find.rb on JRuby: the default Java heap cap (1/4 of memory) is too small for its 100M element array. It failed on JRuby 9.1 in CI (3554MB cap) and on JRuby 10 locally (2232MB). Both now get -J-Xmx6g. - On main (SHARE=1), JRuby 9.1 crashed every benchmark when sharing: its bundled jruby-openssl fails the TLS handshake with ips.fastruby.io ("Received fatal alert: handshake_failure"). The Gemfile gives JRuby before 9.2 a newer jruby-openssl (0.14.6 resolves). JRuby 10 already connects, so it keeps its own.
1 parent 21a33f3 commit 2e65fd1

5 files changed

Lines changed: 19 additions & 8 deletions

File tree

‎Gemfile‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ gem 'e2mmap'
1010
# does not even parse on Ruby 2.1.
1111
gem 'ostruct' if RUBY_VERSION >= '3.4'
1212

13+
# JRuby 9.1's bundled jruby-openssl cannot complete a TLS handshake with
14+
# ips.fastruby.io, so sharing results (SHARE=1) crashed every benchmark.
15+
gem 'jruby-openssl', '>= 0.10' if RUBY_ENGINE == 'jruby' && Gem::Version.new(JRUBY_VERSION) < Gem::Version.new('9.2')
16+
1317
gem 'rake'

‎code/hash/dig-vs-[]-vs-fetch.rb‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
h = { a: { b: { c: { d: { e: "foo" } } } } }
44

55
Benchmark.ips do |x|
6-
x.report "Hash#dig" do
7-
h.dig(:a, :b, :c, :d, :e)
6+
if RUBY_VERSION >= "2.3.0"
7+
x.report "Hash#dig" do
8+
h.dig(:a, :b, :c, :d, :e)
9+
end
810
end
911

1012
x.report "Hash#[]" do

‎code/hash/slice-native-vs-before-native.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def slow
4141
end
4242

4343
Benchmark.ips do |x|
44-
x.report('Hash#native-slice ') { fastest }
44+
x.report('Hash#native-slice ') { fastest } if RUBY_VERSION >= '2.5.0'
4545
x.report('Array#each ') { faster }
4646
x.report('Array#each_w/_object') { fast }
4747
x.report('Hash#select-include ') { slow }

‎code/string/remove-extra-spaces-or-other-chars.rb‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
require 'benchmark/ips'
22

3-
PASSAGE = <<~LIPSUM
4-
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
5-
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
6-
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
7-
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
3+
# A plain heredoc, not <<~, which is Ruby 2.3+ (older Rubies cannot parse the file at all).
4+
PASSAGE = <<LIPSUM
5+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
6+
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
7+
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
8+
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
89
LIPSUM
910

1011
raise unless PASSAGE.gsub(/ +/, " ") == PASSAGE.squeeze(" ")

‎compose.yaml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ x-benchmark: &benchmark
1010
working_dir: /app
1111
environment:
1212
- SHARE
13+
# Only JRuby reads it. Java's default heap cap (1/4 of memory) is too small
14+
# for code/array/bsearch-vs-find.rb's 100M element array: JRuby 9.1 fails
15+
# even on 16 GB CI runners, JRuby 10 on smaller machines.
16+
- JRUBY_OPTS=-J-Xmx6g
1317
entrypoint: ["/app/docker/run-benchmarks.sh"]
1418

1519
services:

0 commit comments

Comments
 (0)