Inspect directly into a RubyString and avoid StringBuilder/char[]. #4128

Merged
merged 2 commits into from Oct 12, 2016

Projects

None yet

2 participants

@headius
Member
headius commented Sep 1, 2016

This should reduce the overhead of inspecting by avoiding the
intermediate StringBuilder/char[] and subsequent conversion to
byte[]. There are a few extra objects created along the way
(java.lang.String.getBytes, RubyString for class name, etc) but
overall memory use should reduce around 3x: a US-ASCII
string would need 2x byte size in the StringBuilder, and the
builder is still alive when we create the eventual byte[] for a
total of 3x max memory use during inspect.

Relates to #4127, but does not constitute a fix for memory issues
there.

@headius headius added this to the JRuby 9.1.5.0 milestone Sep 1, 2016
@headius
Member
headius commented Sep 1, 2016

Inspect perf comparison.

Script:

obj = top = Object.new
100.times do
  obj2 = Object.new
  obj.instance_variable_set :@obj, obj2
  obj = obj2
end
loop do
  t = Time.now
  1000.times { top.inspect }
  puts Time.now - t
end

Before:

1.306
0.918
0.95
0.883
0.915
0.956
0.903
0.876
0.899
0.89

After:

0.339
0.18
0.184
0.205
0.148
0.155
0.195
0.153
0.149
0.198
0.153
@enebo enebo modified the milestone: JRuby 9.1.5.0, JRuby 9.1.6.0 Sep 7, 2016
headius added some commits Sep 1, 2016
@headius headius Inspect directly into a RubyString and avoid StringBuilder/char[].
This should reduce the overhead of inspecting by avoiding the
intermediate StringBuilder/char[] and subsequent conversion to
byte[]. There are a few extra objects created along the way
(java.lang.String.getBytes, RubyString for class name, etc) but
overall memory use should reduce around 3x: a US-ASCII
string would need 2x byte size in the StringBuilder, and the
builder is still alive when we create the eventual byte[] for a
total of 3x max memory use during inspect.

Relates to #4127, but does not constitute a fix for memory issues
there.
a40621d
@headius headius Use String form since it handles anonymous classes properly.
8131146
@enebo enebo merged commit 256042b into jruby:master Oct 12, 2016

0 of 2 checks passed

continuous-integration/appveyor/pr AppVeyor build failed
Details
continuous-integration/travis-ci/pr The Travis CI build failed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment