Commit Graph

6 Commits

Author SHA1 Message Date
Ömer Ağacan bf97e28b6d [dart2wasm] Fix reporting measurements in WasmJSInterop benchmarks
benchmark_harness's `measureFor` returns in microseconds, but we
currently show the numbers with the unit "ns".

Convert the microseconds reported by benchmark_harness to nanoseconds
when reporting.

We could also report in microseconds, but the numbers would be very
small, with a few zeros before fractional digits. So keep reporting in
nanoseconds.

Change-Id: I189190b2139c8e2d39b8bef84159585ab0967980
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/436904
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2025-06-25 06:49:29 -07:00
Nicholas Shahan 1b5df759b8 [benchmark] Cleanup lint violations
Fix violations of lints that I expect have no influence on the
performance characteristics of this benchmark:

* avoid_init_to_null
* directives_ordering
* prefer_single_quotes

Change-Id: I50b507405abf9eb75c2fba688a9588a2fa84bab7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433268
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2025-06-09 15:40:57 -07:00
Martin Kustermann 6e71aa8769 [dart2wasm] Move benchmarks/WasmJSInterop/{,dart/}WasmJSInterop.dart
This will put it into a place where the benchmarking system will find it.

Change-Id: I0ae3762ada89b4b4b71932eb565853a291935fcc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429300
Reviewed-by: Ömer Ağacan <omersa@google.com>
2025-05-19 03:50:29 -07:00
Ömer Ağacan 42e3a7a8fd [dart2wasm] Add more JS interop benchmarks
In prep for [1], benchmark `dartify` performance when converting JS call
return values to Dart values.

[1]: https://dart-review.googlesource.com/c/sdk/+/424021

Change-Id: I43549276f0ccdfefcc689c0574f82cad4a856aa5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/424940
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2025-04-28 02:33:12 -07:00
Ömer Ağacan db448306dc [dart2wasm] Pass Dart double as f64 to JS interop
Don't convert Dart `double`s to `externref`s when calling JS interop
functions, pass them as `double`.

We pass other unboxed values (`int`s and `bool`s) as `externref`s, as
before:

- `int`s are most efficiently passed as `externref`s, as small integers
  can be converted to `i31ref` and externalized without allocation.

- `bool`s passed as `i32` mostly work because JS treats 0 as false and
  everything else as true, but the values can still be observed as
  numbers rather than bools, which causes some test failures.

Changes:

- Make raw interop procedures take `double` as argument, when the Dart
  type for the interop function argument is non-nullable `double`.

- Pass static type of the value and expected type (by the interop
  function) to `jsifyValue`.

- `jsifyValue` then takes the static type and expected type into account
  to avoid conversions when both are `double`s.

- `jsifyValue` is refactored to avoid the type conversion mapping
  allocation on every call.

New benchmark result before the changes:

    WasmJSInterop.call.void.1ArgsDouble(RunTimeRaw): 0.018275229357798167 ns.

After:

    WasmJSInterop.call.void.1ArgsDouble(RunTimeRaw): 0.014034965034965034 ns.

Issue: https://github.com/dart-lang/sdk/issues/60357
Change-Id: Ia70671f9a8e14f359f1119beda123e94aacdd2cd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/422480
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2025-04-24 01:58:20 -07:00
Ö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