New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Oct 12, 2016

Conversation

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

This comment has been minimized.

Show comment
Hide comment
@headius

headius Sep 1, 2016

Member

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
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 milestones: JRuby 9.1.5.0, JRuby 9.1.6.0 Sep 7, 2016

headius added some commits Sep 1, 2016

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.

@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