mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/psych] Optimize cache with compare_by_identity
Using `compare_by_identity` gives a 4x performance boost on cache hits. Benchmark in https://github.com/JuanitoFatas/fast-ruby/issues/189
This commit is contained in:
parent
c5a445d577
commit
daec109f42
Notes:
git
2020-12-23 15:09:02 +09:00
3 changed files with 5 additions and 2 deletions
|
@ -12,7 +12,7 @@ module Psych
|
|||
def self.dispatch_cache
|
||||
Hash.new do |hash, klass|
|
||||
hash[klass] = :"visit_#{klass.name.gsub('::', '_')}"
|
||||
end
|
||||
end.compare_by_identity
|
||||
end
|
||||
|
||||
if defined?(Ractor)
|
||||
|
|
|
@ -80,7 +80,7 @@ module Psych
|
|||
raise(TypeError, "Can't dump #{target.class}") unless method
|
||||
|
||||
h[klass] = method
|
||||
end
|
||||
end.compare_by_identity
|
||||
end
|
||||
|
||||
def start encoding = Nodes::Stream::UTF8
|
||||
|
|
|
@ -24,6 +24,9 @@ class TestPsychRactor < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_ractor_config
|
||||
# Config is ractor-local
|
||||
# Test is to make sure it works, even though usage is probably very low.
|
||||
# The methods are not documented and might be deprecated one day
|
||||
assert_ractor(<<~RUBY, require_relative: 'helper')
|
||||
r = Ractor.new do
|
||||
Psych.add_builtin_type 'omap' do |type, val|
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue