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

Skip to content

Wasm: Optimize varargs by removing JSArrayConstr #5172

Open
@tanishiking

Description

@tanishiking

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    wasmApplies to the WebAssembly backend only

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions