Summary
Array#include? and Array#index show a significant performance regression in JRuby 10 compared to JRuby 1.7. JRuby 1.7 was notably faster than MRI for these operations, but JRuby 10 has lost that advantage.
Benchmark
require 'benchmark'
array = (1..100_000).to_a
Benchmark.bm(20) do |x|
x.report("Array#include?") do
1000.times { array.include?(99_999) }
end
x.report("Array#index") do
1000.times { array.index(99_999) }
end
end
Results
| Method |
MRI 3.4.7 |
JRuby 1.7.27 |
JRuby 10.0.2.0 |
Regression (10 vs 1.7) |
Array#include? |
0.200s |
0.058s |
0.173s |
3x slower |
Array#index |
0.218s |
0.097s |
0.178s |
1.8x slower |
Key observations:
- JRuby 1.7 was 3x faster than MRI for
Array#include?
- JRuby 10 is now slower than JRuby 1.7, roughly on par with MRI
- Both methods involve linear search, so likely the same root cause
Impact
These are common operations for checking membership and finding positions in arrays. The regression affects any code doing frequent array lookups without using Sets or Hashes.
Environment
- JRuby 10.0.2.0 on Java 21 (Temurin 21.0.9)
- JRuby 1.7.27 on Java 8 (Corretto 8.472)
- MRI 3.4.7
- macOS Darwin 25.1.0
Summary
Array#include?andArray#indexshow a significant performance regression in JRuby 10 compared to JRuby 1.7. JRuby 1.7 was notably faster than MRI for these operations, but JRuby 10 has lost that advantage.Benchmark
Results
Array#include?Array#indexKey observations:
Array#include?Impact
These are common operations for checking membership and finding positions in arrays. The regression affects any code doing frequent array lookups without using Sets or Hashes.
Environment