Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

sjrd
Copy link
Member

@sjrd sjrd commented Aug 29, 2025

When the expr of a cast (including unchecked asInstanceOfs) is a node implemented with a custom JS helper, we now fuse the unboxing/cast operation into the JS-to-Wasm boundary, when possible.

This removes one round-trip to JS. For example, a call to js.Math.cos(x) now results in a single Wasm-to-JS call, where the JS helper has type [f64] -> [f64] in Wasm.

@sjrd sjrd requested a review from gzm0 August 29, 2025 12:25
@sjrd sjrd force-pushed the wasm-fuse-unboxes-into-custom-js-helpers branch 2 times, most recently from 654bf0c to 76e785f Compare September 2, 2025 09:11
When the `expr` of a cast (including unchecked `asInstanceOf`s) is
a node implemented with a custom JS helper, we now fuse the
unboxing/cast operation into the JS-to-Wasm boundary, when possible.

This removes one round-trip to JS. For example, a call to
`js.Math.cos(x)` now results in a single Wasm-to-JS call, where the
JS helper has type `[f64] -> [f64]` in Wasm.
@sjrd sjrd force-pushed the wasm-fuse-unboxes-into-custom-js-helpers branch from 76e785f to 04f8d39 Compare September 7, 2025 13:27
Copy link
Contributor

@tanishiking tanishiking left a comment

Choose a reason for hiding this comment

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

I left a few comments/questions, but otherwise LGTM from my side 👍

Comment on lines +573 to +574
* Exception: two JSBinaryOp's have `tpe == BooleanType`, but this is also
* fine as all the supertypes of `BooleanType` can be used as well.
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean by:

this is also fine as all the supertypes of BooleanType can be used as well.

?

If I understand correctly, it's fine to use castTo = AnyType when tpe = BooleanType (=== and !==) because of val resultType = if (castTo == AnyType) tree.tpe else castTo in genJSBinary/UnaryOp. The helper function returns boolean, not anyref.

Comment on lines +2442 to +2443
if (sourceTpe == AnyType && targetTpeCastableThroughJSWasmBoundary) {
// Try and push the cast inside nodes that use a custom JS helper
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be worth adding some more explanation, similar to what's in the PR description here ?

This removes one round-trip to JS. For example, a call to js.Math.cos(x) now results in a single Wasm-to-JS call, where the JS helper has type [f64] -> [f64] in Wasm.

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.

2 participants