Skip to content

Commit

Permalink
[incremental compiler] Streamline processing of reused/removed builders
Browse files Browse the repository at this point in the history
Suprisingly this doesn't seem to affect performance, but doing basically
the same thing in two different ways is suboptimal.

Change-Id: I1cc52bceb05a0af4d0e0d0574c3599c063cf42a8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/105242
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Kevin Millikin <kmillikin@google.com>
  • Loading branch information
jensjoha authored and commit-bot@chromium.org committed Jun 6, 2019
1 parent 5eff2a0 commit b4d190f
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions pkg/front_end/lib/src/fasta/incremental_compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,26 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
List<LibraryBuilder> reusedLibraries = computeReusedLibraries(
invalidatedUris, uriTranslator,
notReused: notReusedLibraries);
Set<Uri> reusedLibraryUris =
new Set<Uri>.from(reusedLibraries.map((b) => b.uri));
bool removedBuilders = false;
for (Uri uri in new Set<Uri>.from(dillLoadedData.loader.builders.keys)
..removeAll(reusedLibraryUris)) {
LibraryBuilder builder = dillLoadedData.loader.builders.remove(uri);
userBuilders?.remove(uri);

bool removedDillBuilders = false;
for (LibraryBuilder builder in notReusedLibraries) {
CompilerContext.current.uriToSource.remove(builder.fileUri);
removedBuilders = true;

LibraryBuilder dillBuilder =
dillLoadedData.loader.builders.remove(builder.uri);
if (dillBuilder != null) {
removedDillBuilders = true;
userBuilders?.remove(builder.uri);
}

// Remove component problems for libraries we don't reuse.
if (remainingComponentProblems.isNotEmpty) {
Library lib = builder.target;
removeLibraryFromRemainingComponentProblems(lib, uriTranslator);
}
}
if (removedBuilders) {

if (removedDillBuilders) {
dillLoadedData.loader.libraries.clear();
for (LibraryBuilder builder in dillLoadedData.loader.builders.values) {
dillLoadedData.loader.libraries.add(builder.target);
Expand All @@ -264,16 +273,6 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
.addAll(oldDillLoadedData.loader.libraries);
}

for (LibraryBuilder builder in notReusedLibraries) {
Library lib = builder.target;
CompilerContext.current.uriToSource.remove(builder.fileUri);

// Remove component problems for libraries we don't reuse.
if (remainingComponentProblems.isNotEmpty) {
removeLibraryFromRemainingComponentProblems(lib, uriTranslator);
}
}

if (hierarchy != null) {
List<Library> removedLibraries = new List<Library>();
for (LibraryBuilder builder in notReusedLibraries) {
Expand All @@ -289,7 +288,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
" of ${userCode.loader.builders.length} libraries");
}

await loadEnsureLoadedComponents(reusedLibraryUris, reusedLibraries);
await loadEnsureLoadedComponents(reusedLibraries);

KernelTarget userCodeOld = userCode;
userCode = new KernelTarget(
Expand Down Expand Up @@ -407,13 +406,13 @@ class IncrementalCompiler implements IncrementalKernelGenerator {

/// Internal method.
Future loadEnsureLoadedComponents(
Set<Uri> reusedLibraryUris, List<LibraryBuilder> reusedLibraries) async {
List<LibraryBuilder> reusedLibraries) async {
if (modulesToLoad != null) {
bool loadedAnything = false;
for (Component module in modulesToLoad) {
bool usedComponent = false;
for (Library lib in module.libraries) {
if (!reusedLibraryUris.contains(lib.importUri)) {
if (!dillLoadedData.loader.builders.containsKey(lib.importUri)) {
dillLoadedData.loader.libraries.add(lib);
dillLoadedData.addLibrary(lib);
reusedLibraries.add(dillLoadedData.loader.read(lib.importUri, -1));
Expand Down

0 comments on commit b4d190f

Please sign in to comment.