- Notifications
You must be signed in to change notification settings - Fork396
Description
Currently in Scala.js, varargs call is translated to the IRjs.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 likenew WrappedArray$ofInt(ArrayValue(1, 2, 3))
(ornew ArraySeq$ofInt(...)
on 2.13)
And take a micro benchmark usingtanishiking/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 showsscala.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 withscala.Array
-based varargs.
We want to somehow virtualize the varargs IR, and translate to the appropriate IR at the optimizer (or backend).