Skip to content

Commit

Permalink
Stop requiring stringio dynamically (#219)
Browse files Browse the repository at this point in the history
`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
  • Loading branch information
jsvd authored Nov 6, 2024
1 parent 519ae6c commit ed9168e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rexml/source.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# coding: US-ASCII
# frozen_string_literal: false

require "stringio"
require "strscan"

require_relative 'encoding'
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ed9168e

Please sign in to comment.