Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Unified Diff: sdk/lib/_internal/compiler/implementation/deferred_load.dart

Issue 221663005: Load deferred chunks in the right order. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/compiler/implementation/deferred_load.dart
diff --git a/sdk/lib/_internal/compiler/implementation/deferred_load.dart b/sdk/lib/_internal/compiler/implementation/deferred_load.dart
index 298c7204bec55f56319c2b2e547f2051b9386842..b93629c73a70e2c3111b5d1928f435e803f81657 100644
--- a/sdk/lib/_internal/compiler/implementation/deferred_load.dart
+++ b/sdk/lib/_internal/compiler/implementation/deferred_load.dart
@@ -119,10 +119,15 @@ class DeferredLoadTask extends CompilerTask {
/// Will be `true` if the program contains deferred libraries.
bool splitProgram = false;
- /// A mapping from the name of a [DeferredLibrary] annotation to all dependent
- /// output units.
- final Map<String, Set<OutputUnit>> hunksToLoad =
- new Map<String, Set<OutputUnit>>();
+ /// A mapping from the name of a defer import to all the output units it
+ /// depends on in a list of lists to be loaded in the order they appear.
+ ///
+ /// For example {"lib1": [[lib1_lib2_lib3], [lib1_lib2, lib1_lib3],
+ /// [lib1]]} would mean that in order to load "lib1" first the hunk
+ /// lib1_lib2_lib2 should be loaded, then the hunks lib1_lib2 and lib1_lib3
+ /// can be loaded in parallel. And finally lib1 can be loaded.
+ final Map<String, List<List<OutputUnit>>> hunksToLoad =
+ new Map<String, List<List<OutputUnit>>>();
final Map<Import, String> importDeferName = new Map<Import, String>();
/// A mapping from elements and constants to their output unit. Query this via
@@ -608,15 +613,26 @@ class DeferredLoadTask extends CompilerTask {
for (OutputUnit outputUnit in allOutputUnits) {
computeOutputUnitName(outputUnit);
}
+ List sortedOutputUnits = new List.from(allOutputUnits);
+ // Sort the outputunits in descending order of the number of imports they
floitsch 2014/04/02 09:32:48 output units
sigurdm 2014/04/02 11:25:30 Done.
+ // include.
floitsch 2014/04/02 09:32:48 Explain why this is necessary and enough.
sigurdm 2014/04/02 11:25:30 I tried to explain it - hope it is not too verbose
+ sortedOutputUnits.sort((a, b) => b.imports.length - a.imports.length);
// For each deferred import we find out which outputUnits to load.
for (Import import in _allDeferredImports.keys) {
if (import == _fakeMainImport) continue;
- hunksToLoad[importDeferName[import]] = new Set<OutputUnit>();
- for (OutputUnit outputUnit in allOutputUnits) {
+ hunksToLoad[importDeferName[import]] = new List<List<OutputUnit>>();
+ int lastNumberOfImports = 0;
+ List<OutputUnit> currentLastList;
+ for (OutputUnit outputUnit in sortedOutputUnits) {
if (outputUnit == mainOutputUnit) continue;
if (outputUnit.imports.contains(import)) {
- hunksToLoad[importDeferName[import]].add(outputUnit);
+ if (outputUnit.imports.length != lastNumberOfImports) {
+ lastNumberOfImports = outputUnit.imports.length;
+ currentLastList = new List<OutputUnit>();
+ hunksToLoad[importDeferName[import]].add(currentLastList);
+ }
+ currentLastList.add(outputUnit);
}
}
}

Powered by Google App Engine
This is Rietveld 408576698