-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Introduce ArrayList type that will map to native js Array #30772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@rakudrama @jmesserly Any thoughts on this? While this issue seems insignificant, List iteration/manipulation performance is major issue in our code. In most of times code that work with List ends up with calling interceptor methods for all operations. |
I think access to the built-in List types would be useful. I see the what you describe in many places. @floitschG This is a question for the Libraries team. Whatever we do, we need to support it widely to permit sharing of business logic between Dart web apps and Flutter mobile apps. One problem is that on the VM there are several types (growable, fixed-length and immutable (const-like) Lists are three different types), but in JavaScript and dart2js there is one (JavaScript Array is used for all variants). Another problem is that the benefits might be transient. Some library might implement a fake version of that type, bringing us back to there being many types and a need for getInceptor, e.g. class MockArrayList<T> implements ArrayList<T> { ... } There are coding styles that can help dart2js's type analysis. class ... {
final _list = []; // Trivial inference. It feels counterintuitive, but you might get better inference results from wrapping arrays to exploit the above trivial inference. One thing we are considering is specializing the library code for (JS)Array. Today if you write |
I'm strongly in favor of this, for what it's worth. EDIT: though we would want this type to be non-implementable/non-extensible, similar to some of the existing dart:core types. |
+1. The other option in my mind is creating a library of JS-level primitives for optimization: /// A `List`-like object guaranteed to be 1:1 mapped to a JavaScript `Array`.
///
/// May be used internally in frameworks that are browser-only in order to avoid
/// interceptors and other de-optimized code in Dart to JavaScript compilers that
/// needs to support polymorphic Dart `List` types.
abstract class JSArray<T> {
// Assume compilers can know new JSArray([1, 2, 3]) really means [1, 2, 3]
external JSArray(List<T> from);
T operator[](int index);
void operator[]=(int index, T value);
List<T> toDartList();
} |
Here are other silly ideas: #30870 |
Another option that would work for us is new primitive |
I'm interested in someone doing an experiment to see how much we can get from wrappers which help dart2js with inference. I don't have the capacity to follow up on this until next year. This library contains |
tl;dr: I don't see this happening in the core platform libraries. Most of the optimizations here are really JavaScript only, and would detract from the non-JavaScript APIs. A We keep the implementation classes for Long ago, in 2012, we briefly had a |
Currently there is no way to specify type that is "default" List implementation. Dart2js uses type inference for optimizations, however in real world it is unable infer type in most cases. What I suggest is to add unextandable ArrayList type in dart:collection that dart2js will know about.
The text was updated successfully, but these errors were encountered: