Skip to content

Commit

Permalink
Remove 'require' from hot path to allow multi-threaded parsing in JRuby
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 Oct 30, 2024
1 parent 519ae6c commit a894533
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
Expand Up @@ -2,6 +2,7 @@
# frozen_string_literal: false

require "strscan"
require "stringio"

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 a894533

Please sign in to comment.