Skip to content
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

@headius
Copy link
Member

@headius 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
Copy link
Member Author

@headius 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 2 commits 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 force-pushed the headius:lighter_inspect branch from fd42519 to 8131146 Sep 30, 2016
@enebo enebo merged commit 256042b into jruby:master Oct 12, 2016
0 of 2 checks passed
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
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.