This CL copies and modifies hash map and set base class `_HashBase`
currently shared with the VM, to improve types of the fields.
The Wasm struct for hash map and set objects was previously:
(type $_HashBase (sub $Object (struct
(field $field0 i32)
(field $field1 (mut i32))
(field $field2 (mut (ref null $Object))) ;; _index
(field $field3 (mut i64))
(field $field4 (mut (ref $Object))) ;; _data
(field $field5 (mut i64))
(field $field6 (mut i64)))))
Now:
(type $_HashBase (sub $Object (struct
(field $field0 i32)
(field $field1 (mut i32))
(field $field2 (mut (ref $Array<WasmI32>))) ;; _index
(field $field3 (mut i64))
(field $field4 (mut (ref $Array<Object?>))) ;; _data
(field $field5 (mut i64))
(field $field6 (mut i64)))))
_index and _data fields are now non-nullable Wasm arrays. This removes
downcasts and one layer of indirection when accessing the elements. In
addition, when accessing `_index` this eliminates unboxing the integers.
Fixes#54961.
Change-Id: I4e6bd5129c7c57f5716ccb23e46060d73ffca217
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/354843
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
The dart2wasm compiler treats wasm arrays of objects/ints/floats pretty
much the same, there's no reason to have complicated class hierarchy and
different kinds of wasm array classes.
Also: We rely on all operations on wasm arrays (and other built-in
types) to be handled on the call site. Wasm arrays are not dart objects,
don't support virtual dispatch. So we make operations operating on the
wasm types extensions.
This also makes now loads and stores into the wasm arrays simple `[]` and
`[]=` operations. We still have special extensions for reading/writing
to integer/double arrays that not only read/write but also
sign-extend/zero-extend and operate on Dart's `int` / `double`.
The compiler will allow `WasmArray<X>(length)` for types `X` that have
default-value in wasm arrays (nullable / integer / double types) and
have another `WasmArray<X>.filled(length, X)` for non-nullable reference
types.
Overall this reduces LOCs and simplifies things
Change-Id: I885bed3dfd1c602dc7b0747c69927d464376383d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340881
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Refactor `JSStringImpl` to use the js-string-builtins API[1].
When the module `WebAssembly.String` is not available we define a
"polyfill" with the previous imports, so this change is backwards
compatible.
Also updates some of the methods to use avoid multiple `this.length`
calls (which do an FFI call), and use unchecked getters when possible.
A new library `dart:_error_utils` is introduced for faster range and
index checks when the length (or max value) is known to be positive
(e.g. when it's the length of a string).
For now only `JSStringImpl` and `operator []` and `operator []=` of
`JSArrayImpl` are updated to use the new range and index checks. Rest of
the libraries will be updated separately.
[1]: https://github.com/WebAssembly/js-string-builtins
CoreLibraryReviewExempt: dart2wasm specific library change.
Change-Id: I9436def0cfe59c631f6f4e15ea06cc18a47a738e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335043
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
This is a reland of commit b9b7de14e0
Previous version broke engine tests because of incorrect array impl
class (e.g. `JSUint16ArrayImpl`) to JS array externref conversion. Since
array implementation classes now store an `externref` to a `DataView`,
we can't use `toExternRef`, we need to use the new `toJSArrayExternRef`.
Original change's description:
> [dart2wasm] Use DataView in JS typed arrays
>
> Refcator JS typed array classes to store JS `DataView`s (instead of JS
> typed array with the matching type), and use V8's new optimized
> `DataView` imports.
>
> Brings JS typed array class performance from unusable to reasonable
> levels. In `SkeletalAnimation` benchmark:
>
> - Before: 1444 us.
> - After: 101 us.
>
> Future work:
>
> - Make immutable classes extend the mutable ones. This will allow `[]`
> calls to be always inlined in JSCM.
>
> - Move list mixin applications from the base class to implementation
> classes. This will allow members like `elementAt`, `forEach` etc. to
> have direct calls to other methods of the same class.
>
> - Try adding a `length` field to avoid JS calls in bounds checks.
>
> Change-Id: Ief6165fe9c4a825072077db820b105c4fca30dce
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/328920
> Reviewed-by: Aske Simon Christensen <askesc@google.com>
> Commit-Queue: Ömer Ağacan <omersa@google.com>
Change-Id: If913aed837d09570b82b0f6dcb9553abb17fd708
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/334468
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
This reverts commit b9b7de14e0.
Reason for revert: Dart to Engine rolls are failing, please see
https://github.com/flutter/engine/runs/18494538711
Original change's description:
> [dart2wasm] Use DataView in JS typed arrays
>
> Refcator JS typed array classes to store JS `DataView`s (instead of JS
> typed array with the matching type), and use V8's new optimized
> `DataView` imports.
>
> Brings JS typed array class performance from unusable to reasonable
> levels. In `SkeletalAnimation` benchmark:
>
> - Before: 1444 us.
> - After: 101 us.
>
> Future work:
>
> - Make immutable classes extend the mutable ones. This will allow `[]`
> calls to be always inlined in JSCM.
>
> - Move list mixin applications from the base class to implementation
> classes. This will allow members like `elementAt`, `forEach` etc. to
> have direct calls to other methods of the same class.
>
> - Try adding a `length` field to avoid JS calls in bounds checks.
>
> Change-Id: Ief6165fe9c4a825072077db820b105c4fca30dce
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/328920
> Reviewed-by: Aske Simon Christensen <askesc@google.com>
> Commit-Queue: Ömer Ağacan <omersa@google.com>
Change-Id: Iba46cfc409805bcd6f86bcc52a06ed8d54eea671
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335026
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Refcator JS typed array classes to store JS `DataView`s (instead of JS
typed array with the matching type), and use V8's new optimized
`DataView` imports.
Brings JS typed array class performance from unusable to reasonable
levels. In `SkeletalAnimation` benchmark:
- Before: 1444 us.
- After: 101 us.
Future work:
- Make immutable classes extend the mutable ones. This will allow `[]`
calls to be always inlined in JSCM.
- Move list mixin applications from the base class to implementation
classes. This will allow members like `elementAt`, `forEach` etc. to
have direct calls to other methods of the same class.
- Try adding a `length` field to avoid JS calls in bounds checks.
Change-Id: Ief6165fe9c4a825072077db820b105c4fca30dce
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/328920
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
- Use `array.copy` and `array.fill` when possible.
- Use the Wasm array directly (instead of `[]` and `[]=`) when possible
to avoid redundant bounds checks.
- `_GrowableList.insert` is rewritten to avoid a redundant write when
the element is not added to the end.
- Remove redundant bounds checks when calling `Lists.copy`.
Change-Id: I08d96b56201cbb4ff24ca969b7fde8bcc1315e4b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/315120
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
This is an internal library not meant to be used in application code.
CoreLibraryReviewExempt: Changes only Wasm specific libraries.
Change-Id: I2f5b463382d35a442e782067ef7d9063183fe5e3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292021
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>