[ruby/psych] Avoid calls to require in hotspots

Followup: https://github.com/ruby/psych/pull/686

This single call shows up as 4% of some controller actions
in the lobsters benchmark.

Profile: https://share.firefox.dev/3EqKnhS

https://github.com/ruby/psych/commit/b77bfee092
This commit is contained in:
Jean Boussier 2025-01-30 09:34:01 +01:00 committed by Hiroshi SHIBATA
parent 599fdb9641
commit c1f024f99d
No known key found for this signature in database
GPG Key ID: F9CF13417264FAC2

View File

@ -55,7 +55,8 @@ module Psych
#
# See also Psych::Visitors::Emitter
def yaml io = nil, options = {}
require "stringio"
require "stringio" unless defined?(StringIO)
real_io = io || StringIO.new(''.encode('utf-8'))
Visitors::Emitter.new(real_io, options).accept self