10000 Wasm: Optimize varargs by removing JSArrayConstr · Issue #5172 · scala-js/scala-js · GitHub
[go: up one dir, main page]

Skip to content

Wasm: Optimize varargs by removing JSArrayConstr #5172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tanishiking opened this issue May 16, 2025 · 0 comments
Open

Wasm: Optimize varargs by removing JSArrayConstr #5172

tanishiking opened this issue May 16, 2025 · 0 comments

Comments

@tanishiking
Copy link
Contributor
tanishiking commented May 16, 2025

Currently in Scala.js, varargs call is translated to the IR js.WrappedArray(JSArrayConstr(...)). That requires JS interop for constructing the arguments and accessing its elements. Since Wasm-JS calls are expensive, this is undesirable for performance.

I revisit #5148 that translate varargs to something like new WrappedArray$ofInt(ArrayValue(1, 2, 3)) (or new ArraySeq$ofInt(...) on 2.13)

And take a micro benchmark using tanishiking/scalajs-benchmarks@37c7bd8 (call varargs methods with 0/1/5 arguments, 10000 times). (fastLinkJS, 2.13)

Image

https://colab.research.google.com/drive/17dJmqx9Wv1uhoPx23O1vHTydd_2f7TrA?usp=sharing

The result shows scala.Array-based varargs implementation is more than twice faster on WebAssembly.
(but it is much slower than js.Array on JS, maybe there's better optimization for Wasm than ArraySeq?)


Of course the runtime performance deteriorates in JS with scala.Array-based varargs.

We want to somehow virtualize the varargs IR, and translate to the appropriate IR at the optimizer (or backend).

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

No branches or pull requests

1 participant
0