Skip to content

perf: skip JS stack traces for Java exceptions, write fewer fields per direct call, and check against Object without a set lookup - #116

Merged
Project516 merged 3 commits into
masterfrom
p516/perf-small-fixes
Dec 3, 2026
Merged

Project516 merged 3 commits into
masterfrom
p516/perf-small-fixes

Conversation

@Project516

Copy link
Copy Markdown
Owner

What this changes

Three small costs that showed up in CPU profiles of javac and of a mixed program (collections, streams, sorting, regex, formatting):

  • JavaThrow and PendingThrow extend Error, so V8 captured a JS stack trace for every Java exception thrown, and nothing reads it. They now set Error.stackTraceLimit to 0 around super(), where the engine allows it. In a JS model with a 30-frame stack, a throw costs a quarter as much. JavaThrow's constructor was 1.0% of a javac run.
  • JThread.enter, the frame setup on every direct call between compiled methods (5 to 10% of those profiles), wrote nine frame fields. A frame stays in the pool only while it has nothing spilled, no monitor still to take, and stays direct; a frame that changes those leaves the pool. So enter now writes only the method, bytecode, pc and lock. A fresh pooled frame starts direct.
  • isAssignableTo answers a check against Object, the one class without a superclass, before its set lookup. Storing into an Object[] (as ArrayList.add does) checks exactly that, and was a third of the type-check time in the mixed program.

Tests

  • The pool invariant was checked with a temporary assertion in enter on every frame taken from the pool, over javac compiling 30 files, the mixed program, a cast benchmark, a virtual-thread benchmark and the Exceptions, InlineDeopt, Continuations and Strings programs. It never fired. Those programs and pnpm typecheck pass.
  • Timing on a GitHub-hosted runner, base 5f1835b (perf: compile inlined callees to smaller JS and compare Latin-1 strings natively, speeding string-heavy code 10 to 17% #111's head) against these changes, 6 pairs per workload with the order alternating. Medians, ranges in brackets. No workload changed beyond its range: bench/Bench.java total 914 ms (877 to 929) against 884 ms (849 to 907), javac 30 files 12,997 ms (12,515 to 14,163) against 13,117 ms (12,378 to 14,024), the mixed program 2,101 ms against 2,101 ms. The gains are small and deterministic (fewer stores per call, no stack walk per throw) rather than visible above runner noise.

Noticed, not fixed

  • Routing virtual calls through the shared rt.callv helper cut javac's generated JS by 12% and its time by 5.5%, but made steady-state code 4 to 8% slower, because V8 cannot inline call targets through a shared helper. Limited to call sites the interpreter never ran before compiling, it saved only 2.9% of the JS. Not included.

@coderabbitai

coderabbitai Bot commented Dec 3, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 4 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 28aa9cf1-652c-4c84-b0a4-9b062c90447d
Commits

Reviewing files that changed from the base of the PR and between d16f3b4 and e97d175.

Files selected for processing: 2

  • src/runtime.ts
  • src/thread.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@project516-review-bot project516-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR adds an Object fast path to isAssignableTo in src/runtime.ts, disables V8 stack trace capture around JavaThrow and PendingThrow construction in src/thread.ts, and reduces per-call frame field writes in JThread.enter by relying on pool cleanliness for sp, locals, stack, needLock, and direct.


review-bot, model nvidia/nemotron-3.5-super-vl:free, verdict approve

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.

1 participant