Use Java 9 stack walking to reduce the cost of #caller and friends#5500
Merged
headius merged 2 commits intojruby:masterfrom Dec 8, 2018
Merged
Use Java 9 stack walking to reduce the cost of #caller and friends#5500headius merged 2 commits intojruby:masterfrom
headius merged 2 commits intojruby:masterfrom
Conversation
c59cce3 to
a85e924
Compare
In preparation for using the StackWalker API on Java 9+ this patch streamifies both the native Java stack elements and the frames from JRuby's interpreter. The former case will allow us to use the StackWalker API to produce those frames lazily, drastically reducing the cost of short stack walks on large stacks. The latter eliminates the copying of the interpreter stack frames and just streams them directly from ThreadContext.
a85e924 to
dd6a5f0
Compare
This improves the performance of limited-depth Kernel#caller by
a substantial amount, dependent on the depth of the stack. For the
following benchmark with a 500-deep stack, the improvement is well
over 10x.
bench_caller_single.rb
```ruby
def foo(depth)
if depth > 0
foo(depth-1)
else
caller(1, 1)
end
end
loop {
t = Time.now
i = 0
while i < 10000
i+=1
foo(500)
end
puts Time.now - t
}
```
Results on 8 and 9:
```
[] ~/projects/jruby $ pickjdk 5 ; jruby blah.rb
New JDK: jdk1.8.0_181.jdk
6.725401
6.5270790000000005
6.555323
^C
[] ~/projects/jruby $ pickjdk 4 ; jruby blah.rb
New JDK: jdk-9.0.4.jdk
0.765762
0.5783969999999999
0.444722
0.442188
0.439658
0.446652
^C
```
dd6a5f0 to
b0444d8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR modifies our logic for building stack traces to be streamable and to use the Java 9 StackWalker API to reduce the load of partial walks.
This is a work in progress.