Conversation
In Binaryen's Inlining pass, multi-use functions (refs > 1) are eligible for inlining at -O3 only if they have no calls and no loops (!hasCalls && !hasLoops), as leaf inlining eliminates function call overhead without code explosion. However, FunctionInfoScanner previously omitted CallIndirect and CallRef from hasCalls tracking. In WasmGC / Java, polymorphic method dispatch is compiled as call_ref. Widely-used utilities containing virtual calls (such as String.valueOf(Object), which performs a null-check and an indirect call to x.toString()) were misclassified as leaf functions and aggressively inlined into thousands of call sites. Inlining non-leaf functions with call_ref does not eliminate the indirect call; it only duplicates the caller-side parameter preparation, null checks, and vtable indexing. This change marks hasCalls = true in visitCallIndirect and visitCallRef so that multi-caller non-leaf functions containing indirect/reference calls are not duplicated across the binary.
tlively
approved these changes
Sep 23, 2026
tlively
left a comment
Member
There was a problem hiding this comment.
This is also strictly beneficial on the Emscripten benchmark suite with a geomean of -0.129% uncompressed and a smaller reduction compressed. Some benchmarks shrink by as much as a few percent uncompressed.
cc @kripken for a second look.
Member
|
@tlively did you see a speed difference, or just size? If the speed looks good, lgtm. I believe the old approach seemed to work well at the time (hence the long comment that is now removed), but many things changed in the optimizer since then 😄 so I can easily believe this is the better heuristic now. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In Binaryen's Inlining pass, multi-use functions (refs > 1) are eligible for inlining at -O3 only if they have no calls and no loops (!hasCalls && !hasLoops), as leaf inlining eliminates function call overhead without code explosion.
However, FunctionInfoScanner previously omitted CallIndirect and CallRef from hasCalls tracking. In WasmGC / Java, polymorphic method dispatch is compiled as call_ref. Widely-used utilities containing virtual calls (such as String.valueOf(Object), which performs a null-check and an indirect call to x.toString()) were misclassified as leaf functions and aggressively inlined into thousands of call sites. Inlining non-leaf functions with call_ref does not eliminate the indirect call; it only duplicates the caller-side parameter preparation, null checks, and vtable indexing.
This change marks hasCalls = true in visitCallIndirect and visitCallRef so that multi-caller non-leaf functions containing indirect/reference calls are not duplicated across the binary.