Project

General

Profile

Bug #13330

Array.include? is slow for symbols

Added by pawelniewie (Pawel Niewiadomski) over 2 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Normal
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

Associated revisions

Revision ad0f8ff7
Added by ko1 (Koichi Sasada) about 2 years ago

Symbol support for opt_eq_func.

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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58895 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 58895
Added by ko1 (Koichi Sasada) about 2 years ago

Symbol support for opt_eq_func.

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

Revision 58895
Added by ko1 (Koichi Sasada) about 2 years ago

Symbol support for opt_eq_func.

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

Revision 58895
Added by ko1 (Koichi Sasada) about 2 years ago

Symbol support for opt_eq_func.

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

History

Updated by ko1 (Koichi Sasada) over 2 years ago

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

Thank you. I'll commit it.

#3

Updated by ko1 (Koichi Sasada) about 2 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]

Also available in: Atom PDF