[ruby-core:80232] [Ruby trunk Bug#13330] Array.include? is slow for symbols

From: pawelniewiadomski@...
Date: 2017-03-19 11:20:10 UTC
List: ruby-core #80232
Issue #13330 has been updated by pawelniewie (Pawel Niewiadomski).


Created PR with a fix https://github.com/ruby/ruby/pull/1540

----------------------------------------
Bug #13330: Array.include? is slow for symbols
https://bugs.ruby-lang.org/issues/13330#change-63669

* Author: pawelniewie (Pawel Niewiadomski)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin16]
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
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



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next