-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Prohibitively high cost of "late" fields and variables #43361
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
I was just made aware (thanks @jonahwilliams) that Dart2JS is entirely relying on CFE lowering as-per here. |
The instance variable is a hard case to optimize well. The Should we just not do that, and simply say that "a dynamic error occurs if when reading an uninitialized late variable"? For the local variable, you are saved by promotion. The The |
@lrhn Yes! |
I found another code size issue with In some cases, dart2js coalesces multiple field initializations into a single statement. // Before null-safety
abstract class HostView<T> {
T component;
ComponentView<T> componentView;
Injector _injector;
} // constructor initialization
_._host_view$_injector = _.componentView = _.component = null; We've found this only occurs when fields with the same initial value are adjacent, and have made a concerted effort to ensure our class layout takes advantage of this optimization. These fields were ideal candidates for // After null-safety
abstract class HostView<T> {
late final T component;
late final ComponentView<T> componentView;
late final Injector _injector;
} // constructor initialization
_.__HostView_component = null;
_.__HostView_component_isSet = false;
_.__HostView_componentView = null;
_.__HostView_componentView_isSet = false;
_.__HostView__injector = null;
_.__HostView__injector_isSet = false; Ideally this could be: _.__HostView_component = _.__HostView_componentView = _.__HostView__injector = null;
_.__HostView_component_isSet = _.__HostView_componentView_isSet = _.__HostView__injector_isSet = false; |
Should this slip to April or are we still trying to land something here? |
Lets slip to April. We have some things we are trying to land, but the more consequential changes are not imminent. |
@sigmundch status? |
lowering changes landed and some improvements made it in, we still have however some optimizations to do and the option to elide initialization checks in |
@sigmundch - moving this to the September milestone. May want to consider -O3 check elision as a separate P1? |
thanks, agree - I filed #46806 to track that separately, but it is all related and we have a few overlapping work items. @fishythefish - feel free to reorganize the issues in a way that it's most helpful to you. |
I am going to close out the issue since there have been improvements in all the reported examples
|
First off, I totally recognize
late
right now is being (in most cases?) directly lowered by the CFE, and not optimized 👍 . I'd probably still recommend usinglate
where it makes the code significantly cleaner, but otherwise I don't quite understand why it's not just trading an NPE on(!.)
for an equally crypticLateInitializeErrorImpl
and a lot of runtime + download cost.I evaluated using
late
in two places today when migrating code, and decided against it in both cases:Instance-level
final
field... and a null-check with an inlined error handler is emitted on every access point:
Using a nullable type and a
!
(and-o3
) was much more terse:Local variable
... compared with nullable
Foo
:/cc @leafpetersen @rakudrama - I can connect with you internally this week to see how I can help further!
The text was updated successfully, but these errors were encountered: