Repository navigation
perf: skip JS stack traces for Java exceptions, write fewer fields per direct call, and check against Object without a set lookup - #116
Conversation
…trace, as nothing reads it
…, as stores into Object[] do
|
Warning Review limit reachedYou'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. View limit details
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. |
There was a problem hiding this comment.
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
What this changes
Three small costs that showed up in CPU profiles of javac and of a mixed program (collections, streams, sorting, regex, formatting):
JavaThrowandPendingThrowextendError, so V8 captured a JS stack trace for every Java exception thrown, and nothing reads it. They now setError.stackTraceLimitto 0 aroundsuper(), 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. Soenternow writes only the method, bytecode, pc and lock. A fresh pooled frame starts direct.isAssignableToanswers a check againstObject, the one class without a superclass, before its set lookup. Storing into anObject[](asArrayList.adddoes) checks exactly that, and was a third of the type-check time in the mixed program.Tests
enteron every frame taken from the pool, over javac compiling 30 files, the mixed program, a cast benchmark, a virtual-thread benchmark and theExceptions,InlineDeopt,ContinuationsandStringsprograms. It never fired. Those programs andpnpm typecheckpass.bench/Bench.javatotal 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
rt.callvhelper 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.