summaryrefslogtreecommitdiff
path: root/ext/psych/lib/psych/visitors/visitor.rb
diff options
context:
space:
mode:
authorMarc-Andre Lafortune <github@marc-andre.ca>2020-12-22 21:29:00 -0500
committerMarc-André Lafortune <github@marc-andre.ca>2020-12-23 01:08:38 -0500
commitdaec109f423e54094800e083fc8a8ca5cbceb866 (patch)
treef78b987b23611916bd7dba30483e51a56fd5f864 /ext/psych/lib/psych/visitors/visitor.rb
parentc5a445d577b786e31c420b5857ad05b954b420ec (diff)
[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
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3953
Diffstat (limited to 'ext/psych/lib/psych/visitors/visitor.rb')
-rw-r--r--ext/psych/lib/psych/visitors/visitor.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/ext/psych/lib/psych/visitors/visitor.rb b/ext/psych/lib/psych/visitors/visitor.rb
index 35f8f81f184..e2585c0c774 100644
--- a/ext/psych/lib/psych/visitors/visitor.rb
+++ b/ext/psych/lib/psych/visitors/visitor.rb
@@ -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)