-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Dart2JS: Use of .runtimeType bloats entire output. #31329
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
Dart 2 will require many instances to carry type parameters too. Any down-cast requires types that might match to have instances with the type parameters available. Since Dart 2 is similar to having Can you quantify "really hurts performance" ? In this very limited example it is possible to eliminate the attachment of the type parameter ( I have some CLs that improve the situation, I'll revisit once Kernel / Dart 2 is done. |
That's what I'm afraid of. Even in production mode?
Can you clarify this? 50% of closures are hit by Function.apply?
I guess I don't... understand why. Dart 2 requires types for optimization and heap soundness, but as long as the output of the code is the same I don't understand why Dart2JS needs to implement the specification. Nobody runs Dart2JS in spec mode in Dart 1 (
Sure! I ran some experiments: https://github.com/matanlurey/dart-js-improvements#rtti In this (contrived, but based on real data internally) example, persisting RTTI added 3x to the size of the binary and slowed down initialization time by 70%, even though the output of both programs (with and without RTTI) were identical. To reproduce: git clone https://github.com/matanlurey/dart-js-improvements.git
pub build benchmark
# Gets size numbers.
pub run jsbench
# Gets runtime initialization cost.
dart tool/patch.dart
dart tool/sample.dart
Honestly we should just eliminate all of these classes of errors in production code.
No rush. I know for sure you can improve it, but I want to improve the concept of Dart2JS so you won't have to try and implement the entire Dart 2.0 specification in the JS runtime. If we're going to do that, we might as well just switch to web assembly now. |
"50% of closures are hit by Function.apply?" No. 50% of closures are used in ways that we cannot prove do not flow into Function.apply. Double negative is not the same as positive, since there are things you can prove true, things you can prove false, and things you can't prove. @matanlurey Can you explain this discrepancy? |
That's really scary. I would hope
Users expect this to fail at runtime: dynamic x = 5;
var y = x as String; But we need a wait to opt-out for things we know are of a type but we can't express it: void _internalFoo(dynamic /*String|int*/ x) {
if (x is String) {
// ..
} else {
var typedX = unsafeCast<int>(x);
// ..
}
}
I don't understand the need to implement Dart features that significantly affect the output and runtime performance of the JavaScript code and VM when they aren't required in most programs. For example, every internal client uses |
I'm guessing that this either is as fixed as it will be, or as priorities allow. Likely we will work on linting or other ways to prevent use of this API. |
FWIW - @johnniwinther implemented a cool optimization so that .runtimeType can be used on certain patterns (like |
Actually, in Dart 2, we never give up! We use the static type of the receiver in uses of
we only reify type parameters on subtypes of
we "only" reify type parameters on all generic classes, but do not for instance give up and assume that all passed type arguments are needed. |
[SDK is latest available in google3]
Master issue: #31328
Emits the following dart2js:
Notice specifically,
H.setRuntimeTypeInfo([], [P.String])
.This isn't used at all in the execution of the problem, but because an unrelated
.runtimeType
was used elsewhere in the program, we assume all reified generics need their types set. This really hurts performance in unpredictable ways and encourages teams not to use generics :-/The text was updated successfully, but these errors were encountered: