Skip to content

Commit ed9168e

Browse files
authored
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 logstash-plugins/logstash-filter-xml#83
1 parent 519ae6c commit ed9168e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/rexml/source.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# coding: US-ASCII
22
# frozen_string_literal: false
33

4+
require "stringio"
45
require "strscan"
56

67
require_relative 'encoding'
@@ -45,7 +46,6 @@ def SourceFactory::create_from(arg)
4546
arg.respond_to? :eof?
4647
IOSource.new(arg)
4748
elsif arg.respond_to? :to_str
48-
require 'stringio'
4949
IOSource.new(StringIO.new(arg))
5050
elsif arg.kind_of? Source
5151
arg

0 commit comments

Comments
 (0)