Project

General

Profile

Actions

Bug #13330

closed

Array.include? is slow for symbols

Added by pawelniewie (Pawel Niewiadomski) about 7 years ago. Updated almost 7 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin16]
[ruby-core:80231]

Description

Looking at the code I noticed that [:test].include?(:test) goes through a general path instead using an optimised version making searching slower than for strings:

Benchmark available at https://github.com/pawelniewie/benchmark-set-array-contains/blob/master/ruby/array_include.rb

Comparison:
array: 1332567.6 i/s
array symbols: 1154135.9 i/s - 1.15x slower

I created a fix for that, after changes you get following results:

Comparison:
array symbols: 1630417.3 i/s
array: 1372269.7 i/s - 1.19x slower

Updated by ko1 (Koichi Sasada) almost 7 years ago

  • Status changed from Open to Assigned
  • Assignee set to ko1 (Koichi Sasada)

Thank you. I'll commit it.

Actions #3

Updated by ko1 (Koichi Sasada) almost 7 years ago

  • Status changed from Assigned to Closed

Applied in changeset trunk|r58895.


Symbol support for opt_eq_func.

  • vm_insnhelper.c (opt_eq_func): optimize for symbol comparison.
    [Bug #13330] [fix GH-1540]
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0