Files
sdk/benchmarks
Ömer Ağacan 6952a80978 [dart2wasm] JS interop: pass small ints as i31ref
In V8, the only way to pass a Wasm integer or float to JS without
allocation is by passing it as a 31-bit integer.

This can be done by:

1. Passing as `i32`. If the integer fits into 31 bits it's passed
   without allocation.

2. Passing as externalized `i31ref`.

(1) requires importing the JS function with different signatures: for
each `int` argument we would need a signature with the `i32` as the Wasm
argument type, and another with `externref` (or `f64` if we want to pass
large integers as `f64`).

This is not feasible as with a JS function with N `int` arguments we
would need `2^N` imports. So we implement (2): we import each interop
function with one signature, passing `externref` as the argument, as
before. When the number fits into 31 bits we convert it to an `i31ref`
and externalize it. Otherwise we convert the number to `externref` as
before, by calling the JS function `(o) => o` imported with type `[f64]
-> [externref]`.

New benchmark checks `int` passing for small (31 bit) and large (larger
than 31 bit) integers. Results before:

    WasmJSInterop.call.void.1ArgsSmi(RunTimeRaw): 0.020 ns.
    WasmJSInterop.call.void.1ArgsInt(RunTimeRaw): 0.018 ns.

After:

    WasmJSInterop.call.void.1ArgsSmi(RunTimeRaw): 0.014 ns.
    WasmJSInterop.call.void.1ArgsInt(RunTimeRaw): 0.018 ns.

Issue: https://github.com/dart-lang/sdk/issues/60357
Change-Id: I749001e0e7e9784114415439298c2f3e0fb974b3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/419880
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2025-04-11 04:14:04 -07:00
..
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2022-12-20 12:36:37 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2024-11-18 10:06:01 +00:00
2022-02-14 14:06:34 +00:00