Repository navigation
perf: compile inlined callees to smaller JS and compare Latin-1 strings natively, speeding string-heavy code 10 to 17% - #111
Conversation
…ch loop, cutting javac's generated JS by 4%
…otSpot intrinsifies them, speeding string sorting by about 5%
|
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 57 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 compiles inlined callees as nested labeled blocks with break branches instead of per-callee switch loops, shares one deopt case between regions that rebuild identical frames (taking the exit code from a table), and replaces per-throw NoInline Error allocation with one shared instance. It adds native intrinsics for StringLatin1.equals and StringLatin1.compareTo that compare Latin-1 byte arrays with unsigned byte comparison, and extends the Strings test to all pairs of ten Latin-1 strings including high bytes, prefixes and the empty string. No defect is apparent from the diff; the logic is internally consistent and the reported tests pass.
review-bot, model nvidia/nemotron-3.5-super-vl:free, verdict approve
There was a problem hiding this comment.
The JIT compiles inlined forward-branching callees as nested labeled blocks with break instead of a per-region switch loop, shares one deopt case between regions that rebuild identical frames, and uses a single shared NoInline object instead of allocating a new Error. StringLatin1.equals and compareTo are added as byte-array intrinsics, and the Strings test prints compareTo/equals for ten Latin-1 strings.
review-bot, model nvidia/nemotron-3.5-super-vl:free, verdict approve
What this changes
The JIT inlined every small callee that has a branch, such as
TreeMap.parentOf(p == null ? null : p.parent), as afor(;;){switch(pc)}loop of its own. Inlined callees only branch forward, so they now compile to nested labeled blocks, where a branch is abreak. The deopt handler shares one case between regions that rebuild the same frames and takes the exit code from a table. The inliner'sNoInlinesignal is one shared object instead of a newError, so it no longer captures a JS stack trace each time.StringLatin1.equals([B[B)ZandStringLatin1.compareTo([B[B)Irun as natives, as HotSpot intrinsifies them. The Java versions went through three frames per comparison.Tests
Stringsnow compares every pair of ten Latin-1 strings, including bytes above 127, prefixes and the empty string, and prints the exactcompareTovalues andequalsresults. Output matches HotSpot.Inline,InlineDeopt,JitGuardMiss,warm-jitandwarm-snapshotpass.pnpm typecheckpasses.Generated JS, measured with
JW_JIT_STATS:TreeMap.fixAfterInsertion21,154 to 14,569 bytes (31% less); javac compiling 30 files, 2,402 methods, 7,944,805 to 7,653,076 bytes (3.7% less).Timing on a GitHub-hosted runner, base 6ac5422 against the branch, 6 pairs per workload with the order alternating. Medians, with the range in brackets:
bench/Bench.javatotalBenchobjects (ArrayList<Integer>fill and sum)Noticed, not fixed
JClass.isAssignableTomade the cast benchmark slower (median 3,290 to 3,861 ms): when code casts one object to two interfaces in turn, the cache misses every time and pays a write per cast. Not included.switch(pc)on every iteration. In a plain-JS model of a tight int loop, that is 1.2 to 1.75 times slower than a structured loop.JavacParser.term3, 92 KB, 137 call sites at about 313 characters each).JavaThrowandPendingThrowextendError, so each Java exception thrown captures a JS stack trace that nothing reads: 1.0% of a javac run.