Project

General

Profile

Feature #12996

Optimize Range#===

Added by ksss (Yuki Kurihara) about 4 years ago. Updated almost 4 years ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:78461]

Description

The proposal is that Range#=== optimize by reducing method calls.

Benchmark

$ cat t.rb
i = 0
while i < 1_000_000
  case i
  when 1..1000
  end
  i += 1
end
$ time ./miniruby -e 1
./miniruby -e 1  0.01s user 0.00s system 85% cpu 0.013 total

Before

$ time ./miniruby t.rb
./miniruby t.rb  0.60s user 0.00s system 99% cpu 0.605 total

After

$ time ./miniruby t.rb
./miniruby t.rb  0.41s user 0.00s system 99% cpu 0.420 total

Important point

Break compatibility in this case.

https://github.com/ruby/ruby/blob/80045bc2a9e12012d6d16517ea5cb037e67eb2c1/test/ruby/test_range.rb#L333-L355

I don't know how to fix this issue.
But I think, This is a key sentence maybe.
https://github.com/ruby/ruby/blob/8130ee5c9dea6d1323d41271cc01c8dc5d8bcc5d/range.c#L1176


Files

range-eqq.patch (1.35 KB) range-eqq.patch ksss (Yuki Kurihara), 12/02/2016 05:07 AM
range_eqq2.patch (1.2 KB) range_eqq2.patch ksss (Yuki Kurihara), 05/17/2017 02:14 PM

Related issues

Related to Ruby master - Feature #12612: Switch Range#=== to use cover? instead of include?RejectedActions
Related to Ruby master - Feature #14575: Switch Range#=== to use cover? instead of include?Closednobu (Nobuyoshi Nakada)Actions

Also available in: Atom PDF