From daec109f423e54094800e083fc8a8ca5cbceb866 Mon Sep 17 00:00:00 2001 From: Marc-Andre Lafortune Date: Tue, 22 Dec 2020 21:29:00 -0500 Subject: [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 --- ext/psych/lib/psych/visitors/visitor.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/psych/lib/psych/visitors/visitor.rb') diff --git a/ext/psych/lib/psych/visitors/visitor.rb b/ext/psych/lib/psych/visitors/visitor.rb index 35f8f81f18..e2585c0c77 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) -- cgit v1.2.3