* [ruby-dev:50026] [Ruby trunk Bug#13343] Improve Hash#merge performance
[not found] <redmine.issue-13343.20170321004936@ruby-lang.org>
@ 2017-03-21 0:49 ` watson1978
2017-03-27 5:21 ` [ruby-dev:50046] " Eric Wong
2017-03-27 5:52 ` [ruby-dev:50047] " watson1978
1 sibling, 1 reply; 3+ messages in thread
From: watson1978 @ 2017-03-21 0:49 UTC (permalink / raw
To: ruby-dev
Issue #13343 has been reported by watson1978 (Shizuo Fujita).
----------------------------------------
Bug #13343: Improve Hash#merge performance
https://bugs.ruby-lang.org/issues/13343
* Author: watson1978 (Shizuo Fujita)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v:
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
Hash#merge will be faster around 60%.
### Before
~~~
user system total real
Hash#merge 0.160000 0.020000 0.180000 ( 0.182357)
~~~
### After
~~~
user system total real
Hash#merge 0.110000 0.010000 0.120000 ( 0.114404)
~~~
### Test code
~~~
require 'benchmark'
Benchmark.bmbm do |x|
hash1 = {}
100.times { |i| hash1[i.to_s] = i }
hash2 = {}
100.times { |i| hash2[(i*2).to_s] = i*2 }
x.report "Hash#merge" do
10000.times do
hash1.merge(hash2)
end
end
end
~~~
### Patch
The patch is in https://github.com/ruby/ruby/pull/1533
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 3+ messages in thread
* [ruby-dev:50046] Re: [Ruby trunk Bug#13343] Improve Hash#merge performance
2017-03-21 0:49 ` [ruby-dev:50026] [Ruby trunk Bug#13343] Improve Hash#merge performance watson1978
@ 2017-03-27 5:21 ` Eric Wong
0 siblings, 0 replies; 3+ messages in thread
From: Eric Wong @ 2017-03-27 5:21 UTC (permalink / raw
To: Ruby developers (Japanese); +Cc: ruby-core
watson1978@gmail•com wrote:
> https://bugs.ruby-lang.org/issues/13343
> ----------------------------------------
> Hash#merge will be faster around 60%.
+Cc ruby-core, since your post was English (and I don't read Japanese)
This is promising!
> The patch is in https://github.com/ruby/ruby/pull/1533
We need to check for redefinition of initialize_dup and
initialize_copy methods in Hash for this to be correct.
Unfortunately for people optimizing Ruby, corner-case
redefinition checks are probably necessary :<
Also, I wonder if we can improve rb_funcall to better support
inline caching. rb_funcall API is also bad since it cannot use
inline cache for method lookup. Maybe a better C API can be
introduced for faster function calls from C.
Note: I checked commit c5d74afdb4cfea2a4c9ff432d9da82f0649a1e67
by having a "fetch = +refs/pull/*:refs/remotes/ruby/pull/*"
line in a "remote" section of my .git/config. I did not
use any proprietary API or JavaScript to view your changes.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [ruby-dev:50047] [Ruby trunk Bug#13343] Improve Hash#merge performance
[not found] <redmine.issue-13343.20170321004936@ruby-lang.org>
2017-03-21 0:49 ` [ruby-dev:50026] [Ruby trunk Bug#13343] Improve Hash#merge performance watson1978
@ 2017-03-27 5:52 ` watson1978
1 sibling, 0 replies; 3+ messages in thread
From: watson1978 @ 2017-03-27 5:52 UTC (permalink / raw
To: ruby-dev
Issue #13343 has been updated by watson1978 (Shizuo Fujita).
I followed the behavior of Array's methods such as
~~~
VALUE
rb_ary_sort(VALUE ary)
{
ary = rb_ary_dup(ary);
~~~
It does not check whether initialize_dup/initialize_copy were overridden.
----------------------------------------
Bug #13343: Improve Hash#merge performance
https://bugs.ruby-lang.org/issues/13343#change-63850
* Author: watson1978 (Shizuo Fujita)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v:
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
Hash#merge will be faster around 60%.
### Before
~~~
user system total real
Hash#merge 0.160000 0.020000 0.180000 ( 0.182357)
~~~
### After
~~~
user system total real
Hash#merge 0.110000 0.010000 0.120000 ( 0.114404)
~~~
### Test code
~~~
require 'benchmark'
Benchmark.bmbm do |x|
hash1 = {}
100.times { |i| hash1[i.to_s] = i }
hash2 = {}
100.times { |i| hash2[(i*2).to_s] = i*2 }
x.report "Hash#merge" do
10000.times do
hash1.merge(hash2)
end
end
end
~~~
### Patch
The patch is in https://github.com/ruby/ruby/pull/1533
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-03-27 5:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <redmine.issue-13343.20170321004936@ruby-lang.org>
2017-03-21 0:49 ` [ruby-dev:50026] [Ruby trunk Bug#13343] Improve Hash#merge performance watson1978
2017-03-27 5:21 ` [ruby-dev:50046] " Eric Wong
2017-03-27 5:52 ` [ruby-dev:50047] " watson1978
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).