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

Use Java 9 stack walking to reduce the cost of #caller and friends #5500

Merged
merged 2 commits into from Dec 8, 2018

Conversation

Projects
None yet
1 participant
@headius
Copy link
Member

headius commented Dec 6, 2018

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.

@headius headius added this to the JRuby 9.2.6.0 milestone Dec 6, 2018

@headius headius force-pushed the headius:lazy_stack_trace branch from c59cce3 to a85e924 Dec 7, 2018

Streamify stack trace processing in prep for stack walker.
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.

@headius headius force-pushed the headius:lazy_stack_trace branch from a85e924 to dd6a5f0 Dec 7, 2018

Use backport9 to support lazy stack walking on Java 9+.
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
```

@headius headius force-pushed the headius:lazy_stack_trace branch from dd6a5f0 to b0444d8 Dec 7, 2018

@headius headius merged commit 2a26d30 into jruby:master Dec 8, 2018

1 check failed

continuous-integration/travis-ci/pr The Travis CI build could not complete due to an error
Details

@headius headius deleted the headius:lazy_stack_trace branch Dec 8, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.