From ed9168e187c6c8a0cb244f863c841d8f8fc8effd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Wed, 6 Nov 2024 00:06:51 +0000 Subject: [PATCH] Stop requiring stringio dynamically (#219) `SourceFactory::create_from(String)` will always run the `require 'stringio'` operation. This prevents a multi-threaded JRuby application from parsing xml on separate threads concurrently given that `require` will pass through a synchronized piece of code. An experiment in removing this `require` lead to a 10x performance improvement on 10 threads parsing incoming strings on xml. For more details see https://github.com/logstash-plugins/logstash-filter-xml/issues/83 --- lib/rexml/source.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rexml/source.rb b/lib/rexml/source.rb index 9a9b8f5d..655164f3 100644 --- a/lib/rexml/source.rb +++ b/lib/rexml/source.rb @@ -1,6 +1,7 @@ # coding: US-ASCII # frozen_string_literal: false +require "stringio" require "strscan" require_relative 'encoding' @@ -45,7 +46,6 @@ def SourceFactory::create_from(arg) arg.respond_to? :eof? IOSource.new(arg) elsif arg.respond_to? :to_str - require 'stringio' IOSource.new(StringIO.new(arg)) elsif arg.kind_of? Source arg