Skip to content

Omit the stacktrace for JOniException - #89

Merged
headius merged 1 commit into
jruby:masterfrom
eregon:omit-stacktrace-for-performance
Oct 28, 2026
Merged

headius merged 1 commit into
jruby:masterfrom
eregon:omit-stacktrace-for-performance

Conversation

@eregon

@eregon eregon commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

cc @headius

@headius

headius commented Oct 27, 2026

Copy link
Copy Markdown
Member

I am reluctant to remove the stack trace here. As with other potentially-useful stack traces in JRuby (EAGAIN etc), it could be tied to a property check so it can be enabled if needed. Alternatively, since your use case is to use the compilation as a verification step, we could add an API that allows compilation to report an error condition more cheaply than raising an exception.

@eregon

eregon commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

My thinking is the Java stracktrace would never be useful to a user of JRuby or TruffleRuby (only the Ruby backtrace).
At most it would be useful to debug a JOni issue, but then running the reproducer under a debugger would provide far more than the stacktrace, so IOW I don't see the value of keeping that Java stacktrace.

What do you think, does that make sense?

A system property default no-stacktrace sounds OK, I can do that if you prefer that.

This change would make every interaction with JOni which ends up in an exception significantly faster, as said above this accounted for 8% of a Rails request, which is very expensive.

@headius

headius commented Oct 27, 2026

Copy link
Copy Markdown
Member

What do you think, does that make sense?

JOni has consumers other than JRuby and TruffleRuby. I do not know what their expectations are regarding compilation exceptions and stack traces.

A system property default no-stacktrace sounds OK

It's perhaps less ideal than providing a "trial compilation" or syntax-checking path that doesn't trigger exceptions, but it's the simpler fix to just disable the stack trace and make it configurable. Use property org.joni.enableStackTrace.

I wish the JVM was better about omitting stack traces for transient throw (this is a perfect case) but alas, here we are.

this accounted for 8% of a Rails request

It appears JRuby also does such a "trial compilation". The Rails patch is good (simplifies stringification of the Regexp) but I agree that a change here is appropriate for unpatched releases.

@eregon
eregon force-pushed the omit-stacktrace-for-performance branch from 1812976 to 2aac297 Compare October 28, 2026 21:35
…ace=true

* The stacktrace is not very useful and is very expensive,
  for example for Regexp#to_s on a Regexp like /(?i:a)|(?i:b)/.
* On ruby-bench's railsbench it accounts for about 8% of the request time.
* Rails master has been improved to use #source instead,
  rails/rails#58678,
  but that doesn't affect existing releases.
* The stacktrace can be re-enabled with the org.joni.enableStackTrace
  system property, e.g. for debugging JOni itself.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@eregon
eregon force-pushed the omit-stacktrace-for-performance branch from 2aac297 to c409a46 Compare October 28, 2026 21:36
@eregon

eregon commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

PR updated, the stacktrace is now omitted, unless -Dorg.joni.enableStackTrace=true.

@headius
headius merged commit 82ba5f8 into jruby:master Oct 28, 2026
1 check passed
@headius

headius commented Oct 29, 2026

Copy link
Copy Markdown
Member

I'll put it a release later this evening. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants