diff options
| author | Jean Boussier <jean.boussier@gmail.com> | 2025-01-30 09:34:01 +0100 |
|---|---|---|
| committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2025-02-14 16:13:26 +0900 |
| commit | c1f024f99d4f24dde4ca3c1f35825eba19c413f6 (patch) | |
| tree | f9b42b8a88266e8ac0d94d2cc33e0bc5b169da30 | |
| parent | 599fdb9641afe4a68dc527a2b0be84caa61b3955 (diff) | |
[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
| -rw-r--r-- | ext/psych/lib/psych/nodes/node.rb | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/ext/psych/lib/psych/nodes/node.rb b/ext/psych/lib/psych/nodes/node.rb index 1a4ea5531f..6ae5c59148 100644 --- a/ext/psych/lib/psych/nodes/node.rb +++ b/ext/psych/lib/psych/nodes/node.rb @@ -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 |
