You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently typed data lists use a i8 array as the buffer and read/write one byte at a time. I can't tell from the code why we use a byte array in typed data lists, but I suspect it has to do with JS interop or getting different views of a lists without copying (which would break sharing).
Opening this issue to document the requirements and alternatives.
It's a bit difficult to find where the typed list constructors and accessors are generated, so here are a few links:
We discussed this with @askeksa-google. The main issue here is the views. Example:
import'dart:typed_data';
voidmain() {
Float64List f64s =Float64List.fromList([1.2, 3.4, 5.6]);
print(f64s);
// Uses the same storage with f64sFloat32List f32View =Float32List.sublistView(f64s);
print(f32View);
// Updates f64s
f32View[2] =7.8;
print(f64s);
}
When creating a view we can't copy the original list's array as an update to one of the original list or views need to update all the others.
The solution is to use a byte array as the backing storage which is shared with all of the views. Each view class can then do reads and writes according to their element types.
The problem is, unlike linear memory, Wasm GC arrays don't support reading elements other than the array's declared element type. So when we use an i8 array as the storage type we have to read and write one byte at a time.
It seems to me like this can potentially be considered as an omission in the MVP GC spec, and maybe we can consider adding a "byte array" type that allows reading/writing different sizes in single read/write, similar to linear memory instructions i32.load, i64.load etc. (I think @eyebrowsoffire has some ideas on this)
However this will have to be turned into a proposal and in the best case it will take months before we can use this new array type.
An alternative that doesn't rely on any new platform features is: we optimize the case when a typed array is used directly (or with a view with the same element type) by allocating an array with the right type. The views will have to do the conversions if necessary. For this we also have two options:
We create a view for every conversion. E.g. a view type that reads F64 from I32 array, a view for reading F32 from I32 array and so on.
This will have smaller overhead in views when reading elements of different types, but there will be N^2 view classes. (where N is the number of typed array element types)
We create a single view class for each element type, and add a "read one byte" method to typed arrays. So if I have a F64 array and a F32 view, the view will use the byte read/write methods of the original array.
Optimized code for `_Float64List.[]`
Currently typed data lists use a
i8
array as the buffer and read/write one byte at a time. I can't tell from the code why we use a byte array in typed data lists, but I suspect it has to do with JS interop or getting different views of a lists without copying (which would break sharing).Opening this issue to document the requirements and alternatives.
It's a bit difficult to find where the typed list constructors and accessors are generated, so here are a few links:
sdk/pkg/dart2wasm/lib/intrinsics.dart
Line 1375 in 82b7891
[]
and[]=
:sdk/pkg/dart2wasm/lib/intrinsics.dart
Line 216 in 82b7891
_TypedList._getFloat32
,_TypedList._setInt64
etc.The text was updated successfully, but these errors were encountered: