* [ruby-core:63477] [ruby-trunk - Bug #10003] [Open] Hash#fetch performance issue
[not found] <redmine.issue-10003.20140701220851@ruby-lang.org>
@ 2014-07-01 22:08 ` richard.schneeman
2014-07-01 22:25 ` [ruby-core:63478] [ruby-trunk - Bug #10003] " merch-redmine
2014-07-02 7:11 ` [ruby-core:63497] " normalperson
2 siblings, 0 replies; 4+ messages in thread
From: richard.schneeman @ 2014-07-01 22:08 UTC (permalink / raw
To: ruby-core
Issue #10003 has been reported by Richard Schneeman.
----------------------------------------
Bug #10003: Hash#fetch performance issue
https://bugs.ruby-lang.org/issues/10003
* Author: Richard Schneeman
* Status: Open
* Priority: Normal
* Assignee:
* Category: core
* Target version:
* ruby -v: 2.1.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
It looks like there is a performance issue with Hash#fetch compared to Hash#[]. I found this issue via this gist: https://gist.github.com/jonleighton/3552829. I could not find it reported anywhere on the tracker, forgive me if this is a known issue:
```
require 'benchmark/ips'
h = { foo: :bar }
Benchmark.ips do |r|
r.report('#[]') { h[:foo] }
r.report('#fetch') { h.fetch(:foo) }
end
Calculating -------------------------------------
#[] 124893 i/100ms
#fetch 121729 i/100ms
-------------------------------------------------
#[] 6917857.4 (±20.4%) i/s - 32472180 in 5.008832s
#fetch 4570251.5 (±18.8%) i/s - 22032949 in 5.015712s
```
This is in Ruby 2.1.2
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
* [ruby-core:63478] [ruby-trunk - Bug #10003] Hash#fetch performance issue
[not found] <redmine.issue-10003.20140701220851@ruby-lang.org>
2014-07-01 22:08 ` [ruby-core:63477] [ruby-trunk - Bug #10003] [Open] Hash#fetch performance issue richard.schneeman
@ 2014-07-01 22:25 ` merch-redmine
2014-07-02 7:04 ` [ruby-core:63495] " Eric Wong
2014-07-02 7:11 ` [ruby-core:63497] " normalperson
2 siblings, 1 reply; 4+ messages in thread
From: merch-redmine @ 2014-07-01 22:25 UTC (permalink / raw
To: ruby-core
Issue #10003 has been updated by Jeremy Evans.
I believe this is expected since the Hash#[] call is optimized to call rb_hash_aref (see opt_aref in insns.def), where the Hash#fetch call goes through normal method dispatch. Array#[] calls are similarly optimized to call rb_ary_entry.
----------------------------------------
Bug #10003: Hash#fetch performance issue
https://bugs.ruby-lang.org/issues/10003#change-47521
* Author: Richard Schneeman
* Status: Open
* Priority: Normal
* Assignee:
* Category: core
* Target version:
* ruby -v: 2.1.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
It looks like there is a performance issue with Hash#fetch compared to Hash#[]. I found this issue via this gist: https://gist.github.com/jonleighton/3552829. I could not find it reported anywhere on the tracker, forgive me if this is a known issue:
```
require 'benchmark/ips'
h = { foo: :bar }
Benchmark.ips do |r|
r.report('#[]') { h[:foo] }
r.report('#fetch') { h.fetch(:foo) }
end
Calculating -------------------------------------
#[] 124893 i/100ms
#fetch 121729 i/100ms
-------------------------------------------------
#[] 6917857.4 (±20.4%) i/s - 32472180 in 5.008832s
#fetch 4570251.5 (±18.8%) i/s - 22032949 in 5.015712s
```
This is in Ruby 2.1.2
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
* [ruby-core:63495] Re: [ruby-trunk - Bug #10003] Hash#fetch performance issue
2014-07-01 22:25 ` [ruby-core:63478] [ruby-trunk - Bug #10003] " merch-redmine
@ 2014-07-02 7:04 ` Eric Wong
0 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2014-07-02 7:04 UTC (permalink / raw
To: Ruby developers
Jeremy is correct, Hash#[] (and Array#[]) have optimized dispatch.
I hardly see Hash#fetch used anywhere, and optimizing dispatch for
uncommon cases hurts performance of common cases.
P.S. even if Hash#fetch were optimized, it would still be slower
because it has optional args to parse.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [ruby-core:63497] [ruby-trunk - Bug #10003] Hash#fetch performance issue
[not found] <redmine.issue-10003.20140701220851@ruby-lang.org>
2014-07-01 22:08 ` [ruby-core:63477] [ruby-trunk - Bug #10003] [Open] Hash#fetch performance issue richard.schneeman
2014-07-01 22:25 ` [ruby-core:63478] [ruby-trunk - Bug #10003] " merch-redmine
@ 2014-07-02 7:11 ` normalperson
2 siblings, 0 replies; 4+ messages in thread
From: normalperson @ 2014-07-02 7:11 UTC (permalink / raw
To: ruby-core
Issue #10003 has been updated by Eric Wong.
Jeremy is correct, Hash#[] (and Array#[]) have optimized dispatch.
I hardly see Hash#fetch used anywhere, and optimizing dispatch for
uncommon cases hurts performance of common cases.
P.S. even if Hash#fetch were optimized, it would still be slower
because it has optional args to parse.
----------------------------------------
Bug #10003: Hash#fetch performance issue
https://bugs.ruby-lang.org/issues/10003#change-47540
* Author: Richard Schneeman
* Status: Open
* Priority: Normal
* Assignee:
* Category: core
* Target version:
* ruby -v: 2.1.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
It looks like there is a performance issue with Hash#fetch compared to Hash#[]. I found this issue via this gist: https://gist.github.com/jonleighton/3552829. I could not find it reported anywhere on the tracker, forgive me if this is a known issue:
```
require 'benchmark/ips'
h = { foo: :bar }
Benchmark.ips do |r|
r.report('#[]') { h[:foo] }
r.report('#fetch') { h.fetch(:foo) }
end
Calculating -------------------------------------
#[] 124893 i/100ms
#fetch 121729 i/100ms
-------------------------------------------------
#[] 6917857.4 (±20.4%) i/s - 32472180 in 5.008832s
#fetch 4570251.5 (±18.8%) i/s - 22032949 in 5.015712s
```
This is in Ruby 2.1.2
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-07-02 6:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <redmine.issue-10003.20140701220851@ruby-lang.org>
2014-07-01 22:08 ` [ruby-core:63477] [ruby-trunk - Bug #10003] [Open] Hash#fetch performance issue richard.schneeman
2014-07-01 22:25 ` [ruby-core:63478] [ruby-trunk - Bug #10003] " merch-redmine
2014-07-02 7:04 ` [ruby-core:63495] " Eric Wong
2014-07-02 7:11 ` [ruby-core:63497] " normalperson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).