Skip to content

dart2js: more compact encoding of fields that are always initialized to null #21450

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

Closed
rakudrama opened this issue Oct 28, 2014 · 2 comments
Closed
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. dart2js-optimization type-enhancement A request for a change that isn't a bug web-dart2js

Comments

@rakudrama
Copy link
Member

Many fields are always initialized to null.
We can tell this by looking at the field declarations (are they initialized, and to what) and the generative constructor initializer lists, e.g:

class _StreamImplEvents extends _PendingEvents {
  _DelayedEvent firstPendingEvent = null;
  _DelayedEvent lastPendingEvent = null;
  ...
}

This leads to allocating constructor calls like the following

        t1 = new P._StreamImplEvents(null, null, 0); // all the field initial values.

The synthesized allocating JavaScript constructor looks like this:

  P._StreamImplEvents =
  function _StreamImplEvents(param_firstPendingEvent, param_lastPendingEvent, param_state) {
    this.firstPendingEvent = param_firstPendingEvent;
    this.lastPendingEvent = param_lastPendingEvent;
    this.state = param_state;
  }

It is generated from the field info

  _StreamImplEvents: {
    "^": "_PendingEvents;firstPendingEvent,lastPendingEvent,_state",

The field info could encode the always-null fields, e.g. preceding the field with "+"

  _StreamImplEvents: {
    "^": "_PendingEvents;+firstPendingEvent,+lastPendingEvent,_state",

Now the synthesized constructor has null values in-line:

  P._StreamImplEvents =
  function _StreamImplEvents(param_state) {
    this.firstPendingEvent = null;
    this.lastPendingEvent = null;
    this.state = param_state;
  }

and the calls to the constructor function that omit the always-null parameters:

       t1 = new P._StreamImplEvents(0);

This is a class-local optimization since it is a function of the field declaration initializers and generative constructor initializer lists.

A global version of the optimization would augment these fields with fields with initializers inferred to be null.

@floitschG
Copy link
Contributor

cc @kmillikin.
Removed Type-Defect label.
Added Type-Enhancement, Optimization labels.

@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed triaged labels Mar 1, 2016
@vsmenon vsmenon added the area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. label Jul 20, 2019
@rakudrama
Copy link
Member Author

We no longer 'encode' fields, and the optimization of initializing fields in the constructor is done for simple constants (not just null).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. dart2js-optimization type-enhancement A request for a change that isn't a bug web-dart2js
Projects
None yet
Development

No branches or pull requests

4 participants