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

Unified Diff: pkg/analyzer/lib/src/summary/incremental_cache.dart

Issue 2046223004: Optimize computing library closures - reuse already created closures. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/summary/incremental_cache.dart
diff --git a/pkg/analyzer/lib/src/summary/incremental_cache.dart b/pkg/analyzer/lib/src/summary/incremental_cache.dart
index 111f2eae0b2be8be929cc2e875033a605f2d5d79..f1bc3970551cf02cb36e144fc85d4ce33c833dcc 100644
--- a/pkg/analyzer/lib/src/summary/incremental_cache.dart
+++ b/pkg/analyzer/lib/src/summary/incremental_cache.dart
@@ -275,7 +275,17 @@ class IncrementalCache {
if (refSource == null) {
throw new StateError('Unable to resolve $refUri in $librarySource');
}
- _appendLibraryClosure(closure, refSource);
+ // If we have already the closure for the 'refSource', use it.
+ // Otherwise, continue computing recursively.
+ // It's not the most efficient algorithm, but in practice we might
+ // visit each library multiple times only for the first top-level
+ // bundle requested in `getLibraryClosureBundles`.
+ List<Source> refClosure = _libraryClosureMap[refSource];
+ if (refClosure != null) {
+ closure.addAll(refClosure);
+ } else {
+ _appendLibraryClosure(closure, refSource);
+ }
}
contentSource.importedUris.forEach(appendLibrarySources);
contentSource.exportedUris.forEach(appendLibrarySources);
@@ -400,9 +410,11 @@ class IncrementalCache {
*/
List<Source> _getLibraryClosure(Source librarySource) {
return _libraryClosureMap.putIfAbsent(librarySource, () {
- Set<Source> closure = new Set<Source>();
- _appendLibraryClosure(closure, librarySource);
- return closure.toList();
+ Set<Source> closureSet = new Set<Source>();
+ _appendLibraryClosure(closureSet, librarySource);
+ List<Source> closureList = closureSet.toList();
+ closureList.sort((a, b) => a.fullName.compareTo(b.fullName));
+ return closureList;
});
}
@@ -418,6 +430,15 @@ class IncrementalCache {
List<int> sourceHash = _getSourceContentHash(source);
byteSink.add(sourceHash);
}
+ // When we sort closure sources for two libraries (A, B) we get exactly
+ // the same list of sources for both A and B. So, their hash is exactly
+ // the same. But we use it to store separate summary bundles for
+ // separate libraries. Ideally would be nice to group these libraries
+ // into a single summary bundle. But this would require delaying
+ // saving bundles until we know all of them.
+ // So, for now we make hashes for separate libraries unique be mixing
+ // in the library source again.
+ byteSink.add(_getSourceContentHash(librarySource));
});
});
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698