Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit ae944a6

Browse files
committed
[Incremental compiler] Only re-check package-uris if base-uri changed
When the .packages file has changed we need to re-check all package-uris to see if we need to invalidate the builders (if the file uri for a package uri library (e.g. if the package was upgrade) has changed we have to invalidate it). This translation is semi-expensive though, so if we can avoid it that would be a good thing. This CL caches the "base URI" for packages from the previous run, so we can start by comparing the base-URIs: If the base-uri for a specific package hasn't changed, nor will the actual translation. Only if the base uri has changed we do the actual translation, and thus save many package-to-file-uri translations. An internal benchmark via kernel worker of lots of outline calculations in worker mode with reuse and the incremental compiler (where the .packages file change every time and we have lots of package-uri libraries) goes from ~185 seconds to ~162 seconds. Change-Id: I3ed48b23a590dbf66f8a2379bb88e1b177f1f034 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/103804 Reviewed-by: Kevin Millikin <[email protected]>
1 parent d911d9b commit ae944a6

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

pkg/front_end/lib/src/fasta/incremental_compiler.dart

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
9696
final Component componentToInitializeFrom;
9797
bool initializedFromDill = false;
9898
Uri previousPackagesUri;
99+
Map<String, Uri> previousPackagesMap;
100+
Map<String, Uri> currentPackagesMap;
99101
bool hasToCheckPackageUris = false;
100102
Map<Uri, List<DiagnosticMessageFromJson>> remainingComponentProblems =
101103
new Map<Uri, List<DiagnosticMessageFromJson>>();
@@ -137,6 +139,8 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
137139
hasToCheckPackageUris = hasToCheckPackageUris || bypassCache;
138140
UriTranslator uriTranslator =
139141
await c.options.getUriTranslator(bypassCache: bypassCache);
142+
previousPackagesMap = currentPackagesMap;
143+
currentPackagesMap = uriTranslator.packages.asMap();
140144
ticker.logMs("Read packages file");
141145

142146
if (dillLoadedData == null) {
@@ -831,10 +835,21 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
831835
if (importUri != fileUri && invalidatedUris.contains(fileUri)) {
832836
return true;
833837
}
834-
if (hasToCheckPackageUris &&
835-
importUri.scheme == "package" &&
836-
uriTranslator.translate(importUri, false) != fileUri) {
837-
return true;
838+
if (hasToCheckPackageUris && importUri.scheme == "package") {
839+
// Get package name, check if the base URI has changed for the package,
840+
// if it has, translate the URI again,
841+
// otherwise the URI cannot have changed.
842+
String path = importUri.path;
843+
int firstSlash = path.indexOf('/');
844+
String packageName = path.substring(0, firstSlash);
845+
if (previousPackagesMap == null ||
846+
(previousPackagesMap[packageName] !=
847+
currentPackagesMap[packageName])) {
848+
Uri newFileUri = uriTranslator.translate(importUri, false);
849+
if (newFileUri != fileUri) {
850+
return true;
851+
}
852+
}
838853
}
839854
if (builders[importUri]?.isSynthetic ?? false) return true;
840855
return false;

0 commit comments

Comments
 (0)