Skip to content

Java wasm build flags - #4533

Merged
kddnewton merged 3 commits into
ruby:mainfrom
andreaTP:java-wasm-build-flags
Dec 3, 2026
Merged

kddnewton merged 3 commits into
ruby:mainfrom
andreaTP:java-wasm-build-flags

Conversation

@andreaTP

@andreaTP andreaTP commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Java Wasm: build at -Os, split large methods, ByteArrayMemory for the bytecode fallback

Three independent commits, measured by parsing JRuby's stdlib (825 files) on GitHub-hosted runners with JDK 25, wasi-sdk 33 and Endive 1.3.0. Parse output was identical across all builds.

  • -Os instead of -O2 -Oz (which compiles at -Oz). On Redline, parsing takes 24–26% less time. In JRuby, warm parsing goes from 1.27–1.29x the default parser's time to 0.98–1.06x. x86_64 machine code grows 17% (3.00 → 3.52 MB). -O2 and -O3 save another 8–10%, but add 48–51% machine code and make the bytecode fallback 1.6–2.3x slower. This commit also drops -fno-sanitize=all, -fno-stack-protector and -lc++ -lc++abi, which don't change the module, and -fPIC, which made no measurable difference. --export-all stays, so the exports are unchanged.
  • methodSplitting (experimental in Endive). Prism's largest functions become JVM methods of up to 55 KB, which HotSpot never JIT-compiles. Splitting them makes the bytecode fallback 5–9x faster, and Redline's machine code is byte-identical.
  • ByteArrayMemory for the bytecode fallback: 26–32% less time than the default ByteBufferMemory. It's set only when nativeProvider() is empty, because Redline uses its own native memory.

Tests pass on Redline and with the fallback forced (-Dendive.redline.os.arch=riscv64).

cc. @headius @enebo

`-O2 -Oz` compiled at -Oz. Built at -Os, Prism on Redline takes 24-26%
less time to parse JRuby's standard library than at -Oz, for 17% more
machine code per platform. -O2 and -O3 save another 8-10%, but carry 48-51%
more machine code than -Oz and leave the bytecode fallback 1.6-2.3x as
slow once oversized methods are split.

-fno-sanitize=all, -fno-stack-protector and -lc++ -lc++abi leave the
module byte-identical. -fPIC does not: dropping it makes the module and
its machine code slightly smaller, with no measurable speed difference.

--export-all stays, so the module exports the same symbols and
Prism_ModuleExports keeps its API.
HotSpot never JIT-compiles a method over 8000 bytes of bytecode, and
several of Prism's functions compile to more than that, the largest to
55 KB at -Os, close to the JVM's 64 KB limit. On the bytecode fallback
they stay in the interpreter however hot they get. Endive 1.3.0's
method splitting breaks them up, and the fallback then parses JRuby's
standard library 5-9x as fast. Redline's machine code is byte-identical
with and without it. The option is experimental in Endive.
With method splitting, the fallback takes 26-32% less time to parse
JRuby's standard library on ByteArrayMemory than on Endive's default
ByteBufferMemory. Redline's runner installs its own native memory, so
the memory factory is only set when nativeProvider() is empty.

@kddnewton kddnewton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good to me, but I'll wait for someone from JRuby to approve.

@headius headius left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks great! Using -Os makes so much sense and I'm looking forward to the method splitting experiments.

@kddnewton
kddnewton merged commit f36ee61 into ruby:main Dec 3, 2026
123 checks passed
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.

3 participants