Skip to content

perf: compile inlined callees to smaller JS and compare Latin-1 strings natively, speeding string-heavy code 10 to 17% - #111

Merged
Project516 merged 3 commits into
masterfrom
p516/find-performance-improvements
Dec 3, 2026
Merged

Project516 merged 3 commits into
masterfrom
p516/find-performance-improvements

Conversation

@Project516

@Project516 Project516 commented Dec 3, 2026 •

Copy link
Copy Markdown
Owner

What this changes

The JIT inlined every small callee that has a branch, such as TreeMap.parentOf (p == null ? null : p.parent), as a for(;;){switch(pc)} loop of its own. Inlined callees only branch forward, so they now compile to nested labeled blocks, where a branch is a break. The deopt handler shares one case between regions that rebuild the same frames and takes the exit code from a table. The inliner's NoInline signal is one shared object instead of a new Error, so it no longer captures a JS stack trace each time.

StringLatin1.equals([B[B)Z and StringLatin1.compareTo([B[B)I run as natives, as HotSpot intrinsifies them. The Java versions went through three frames per comparison.

Tests

  • Strings now compares every pair of ten Latin-1 strings, including bytes above 127, prefixes and the empty string, and prints the exact compareTo values and equals results. Output matches HotSpot.

  • Inline, InlineDeopt, JitGuardMiss, warm-jit and warm-snapshot pass. pnpm typecheck passes.

  • Generated JS, measured with JW_JIT_STATS: TreeMap.fixAfterInsertion 21,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:

    workload master branch change
    javac, 30 files 9,002 ms (8,856 to 9,187) 8,768 ms (8,560 to 8,955) -2.6%
    mixed program, round 3 (records, dispatch, sort, regex, format, maps) 1,302 ms (1,282 to 1,353) 1,162 ms (1,157 to 1,210) -10.7%
    sorting 60,000 strings by length then reverse order 406 ms (390 to 421) 356 ms (347 to 372) -12.4%
    casts and sorting 300,000 records by a String field 1,121 ms (1,092 to 1,178) 929 ms (883 to 946) -17.1%
    bench/Bench.java total 584 ms (570 to 598) 580 ms (569 to 589) -0.8%
    Bench objects (ArrayList<Integer> fill and sum) 50.5 ms (49 to 54) 56 ms (49 to 58) +10.9%, ranges overlap
    20,000 virtual threads 612 ms (593 to 631) 635 ms (610 to 649) +3.8%, ranges overlap
    hello world from a boot snapshot 359 ms 358 ms 0%

Noticed, not fixed

  • A one-entry supertype cache in JClass.isAssignableTo made 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.
  • Compiled loops go back through the method's 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.
  • Call sites are 46.5% of the generated JS for javac's largest method (JavacParser.term3, 92 KB, 137 call sites at about 313 characters each).
  • JavaThrow and PendingThrow extend Error, so each Java exception thrown captures a JS stack trace that nothing reads: 1.0% of a javac run.

…otSpot intrinsifies them, speeding string sorting by about 5%
@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 57 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: 060dc12c-fb1c-47fd-9e6c-1c5e5e6f78f3
Commits

Reviewing files that changed from the base of the PR and between 32776b2 and 68a088f.

Files selected for processing: 3

  • src/jit.ts
  • src/natives/strings.ts
  • test/java/Strings.java
  • 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 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

@Project516 Project516 changed the title perf: compile inlined callees to smaller JS and compare Latin-1 strings natively, sorting strings about 5% faster perf: compile inlined callees to smaller JS and compare Latin-1 strings natively, speeding string-heavy code 10 to 17% Dec 3, 2026

@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 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

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