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

set_backtrace should disable backtrace generation on raise #5605

Closed
headius opened this issue Feb 11, 2019 · 0 comments
Closed

set_backtrace should disable backtrace generation on raise #5605

headius opened this issue Feb 11, 2019 · 0 comments
Milestone

Comments

@headius
Copy link
Member

@headius headius commented Feb 11, 2019

Reported by @jeremyevans while improving perf of no-trace flow control exceptions.

The following benchmarks should perform roughly the same. Instead, the one with set_backtrace performs more like a normal exception with a full backtrace.

3-argument raise:

loop do
  t = Time.now
  1000000.times do
    begin
      raise(Exception, '', [])
    rescue Exception
    end
  puts Time.now - t
end

set_backtrace:

loop do
  t = Time.now
  1000000.times do
    begin
      e = Exception.new
      e.set_backtrace([])
      raise e
    rescue Exception
    end
  puts Time.now - t
end

There's some logic missing in JRuby to avoid generating a backtrace if one is manually set.

@headius headius added this to the JRuby 9.2.7.0 milestone Feb 11, 2019
headius added a commit to headius/jruby that referenced this issue Feb 12, 2019
* Request backtrace from exception object before raise, so that
  pre-set backtrace or overridden #backtrace skip native trace
  gathering.
* Eliminate some redundant or unused backtrace-gathering methods.
* Fix Kernel#warn uplevel logic to use partial traces (Java 9).

The fixes here allow two additional ways of blunting the cost of
raising an exception (by eliminating the native stack trace):

* Call Exception#set_backtrace before raising
* Use an Exception subtype that overrides Exception#backtrace

This improves the performance of these scenarios to be roughly
equivalent to the three-arg form of Kernel#raise.

Fixes jruby#5605.
headius added a commit to headius/jruby that referenced this issue Feb 12, 2019
* Request backtrace from exception object before raise, so that
  pre-set backtrace or overridden #backtrace skip native trace
  gathering.
* Eliminate some redundant or unused backtrace-gathering methods.
* Fix Kernel#warn uplevel logic to use partial traces (Java 9).

The fixes here allow two additional ways of blunting the cost of
raising an exception (by eliminating the native stack trace):

* Call Exception#set_backtrace before raising
* Use an Exception subtype that overrides Exception#backtrace

This improves the performance of these scenarios to be roughly
equivalent to the three-arg form of Kernel#raise.

Fixes jruby#5605.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

1 participant