Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Enable dart2js to split output into N files to reduce initial download size #3940

Closed
DartBot opened this Issue · 19 comments

6 participants

@DartBot
Collaborator

This issue was originally filed by andreb...@gmail.com


When using dart2js the generate javascript contains everything required to run the code, but sometimes the application don't need to use the entire code to execute.

An example:
mainPage:
  load the std library and mainPage.dart
configPage:
  load only the configPage.dart code and use the rest that was loaded
in the mainPage

The idea is to have something similar to what is done in GWT (with runAsync) and closure-compiler (with modules).

@kasperl
Collaborator

Added Area-Dart2JS, Triaged labels.

@kasperl
Collaborator

Added this to the Later milestone.

@kasperl
Collaborator

Removed this from the Later milestone.

@kasperl
Collaborator

Added this to the Later milestone.

@kasperl
Collaborator

Set owner to @peter-ahe-google.
Removed this from the Later milestone.
Added this to the M3 milestone.
Added Accepted label.

@peter-ahe-google
Collaborator

Removed Priority-Medium label.
Added Priority-High label.

@peter-ahe-google
Collaborator

Progress so far:

API proposal for deferred loading: https://codereview.chromium.org/11784018/

Compiler API changed to support multiple output files using Sinks/Streams (committed r17749).

Implemented deferred loading of static/top-level functions: https://codereview.chromium.org/12033003/

Missing: deferred loading of classes.

@peter-ahe-google
Collaborator

Added Started label.

@peter-ahe-google
Collaborator

Removed this from the M3 milestone.
Added this to the M4 milestone.

@peter-ahe-google
Collaborator

I have landed the CL with the API (r18637), and the CL for deferred loading of static/top-level functions (r18671).

I'm still working on deferring load of classes.

@sethladd
Owner

Thanks, where is this documented? A quick check of the spec didn't come up with anything.

@peter-ahe-google
Collaborator

There is a new class called DeferredLibrary in dart:async. I don't know where to find up-to-date bleeding_edge documentation, so I cannot give you a link to it.

But this feature is nowhere near complete, please don't announce anything yet.

@sethladd
Owner

For those following along at home: http://api.dartlang.org/docs/bleeding_edge/dart_async.html

Don't worry, just following along. Excited!

@peter-ahe-google
Collaborator

https://codereview.chromium.org/12224010 implements deferred loading of classes.

I'm aware of the following major short-comings that will persist after CL 12224010 is landed:

* The deferred code will often force Isolate.prototype to become a "slow" object. This means that calling top-level or static methods that have been lazily loaded becomes really slow (this also applies to Dart constructors).

* Only the library that is marked with DeferredLibrary is deferred. Instead, we need to perform something like tree-shaking to ensure that stuff only used by the the deferred library doesn't get included in the main JS file.

* Constants using deferred classes are broken.

* You can split the output in at most two files.

All these limitations are short-term, and I'm working on eliminating them. However, I think that once CL 12224010 lands, people can start using this for real apps.

@peter-ahe-google
Collaborator

Deferred loading of classes landed in r18834, and deferred loading of constants landed in r19378.

I'm currently working on computing the transitive closure of deferred libraries to ensure that the initial download doesn't include stuff only needed by a deferred library.

@peter-ahe-google
Collaborator

https://codereview.chromium.org/12525007/ implements basic dependency graph segmentation. This means that the initial download should not be polluted with unneeded code from shared libraries.

@peter-ahe-google
Collaborator

Submitted CL 12525007 as r19793. The compiler will now segment the dependency graph. This should make the initial download much smaller.

@dgrove
Owner

Added C1 label.

@DartBot
Collaborator

This comment was originally written by @seaneagan


The "You can split the output in at most two files" limitation is what I am hitting right now. I am trying to split it into about 170 files. My code is at:

https://github.com/seaneagan/intlx/blob/master/lib/src/plural/load_locale.dart

Each of the 170 correspond to libraries which contain plural rules code for given locales from this directory:

https://github.com/seaneagan/intlx/tree/master/lib/src/plural/locale

Will this amount of files ever be possible/performant? If yes, I'll create a separate issue to track support for more than 2 files. If no, that would be a regression from JavaScript, where this is commonly done.

@sigurdm sigurdm was assigned by DartBot
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.