Description
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)
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).