Skip to content

Consider optimizing trivial case statements #2

@yorickpeterse

Description

@yorickpeterse

Original issue: rubinius/rubinius#3620

Copied here for ease of reading:


Hello,

MRI adopts "jump table"-like optimization for case-when statement if all clauses have trivial immediate values such as Integer and Symbol. How about implementing this optimization in Rubinius?

100000.times do
  case 1000
  when 0
  when 1
  when 2
  ...
  when 999
  end
end
$ time ruby -v t.rb
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]

real    0m0.082s
user    0m0.068s
sys     0m0.012s
# time ruby -v t.rb
rubinius 3.14 (2.2.2 a7ba16db 2016-01-28 3.4.2 JI) [x86_64-linux-gnu]

real    0m2.311s
user    0m2.240s
sys     0m0.064s

(I'm using rubinius/docker.)

Thank you for your consideration,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions