Skip to content

Commit f09edd1

Browse files
jensjohacommit-bot@chromium.org
authored andcommitted
[CFE] Add incremental serializer
Add an incremental serializer that can be used to avoid re-serializing the same thing again and again. It does this by grouping libraries into Components / bundles, serializing them individually and using the concatenated dill feature to output the wanted data --- just potentially faster if we had the data in cache. Note that the serialized output might contain *more* than the input given if we cached the wanted data into a bigger bundle. The output will always be "closed" though, i.e. if the stuff that is included that is too much added a new dependency, that dependency will be included as well. This should generally make it safe, although one can imagine situations where it could pull in lots of dependencies that it wouldn't otherwise have. It is being driven by the incremental compiler which makes sure to invalidate the cache when the data changes. Except for situations where the libraries are changed externally after being serialized, but before being serialized again, where one then wants the updated library serialized, the feature should be safe. Change-Id: I2a504abe6dbb68434c3b04abff13480ef72a6a6e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/120786 Reviewed-by: Johnni Winther <johnniwinther@google.com> Commit-Queue: Jens Johansen <jensj@google.com>
1 parent ff23f54 commit f09edd1

File tree

12 files changed

+889
-27
lines changed

12 files changed

+889
-27
lines changed

pkg/front_end/lib/src/api_prototype/incremental_kernel_generator.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,25 @@ import '../fasta/compiler_context.dart' show CompilerContext;
1717

1818
import '../fasta/incremental_compiler.dart' show IncrementalCompiler;
1919

20+
import '../fasta/incremental_serializer.dart' show IncrementalSerializer;
21+
2022
import '../fasta/scanner/string_scanner.dart' show StringScanner;
2123

2224
import 'compiler_options.dart' show CompilerOptions;
2325

26+
export '../fasta/incremental_serializer.dart' show IncrementalSerializer;
27+
2428
abstract class IncrementalKernelGenerator {
2529
factory IncrementalKernelGenerator(CompilerOptions options, Uri entryPoint,
26-
[Uri initializeFromDillUri, bool outlineOnly]) {
30+
[Uri initializeFromDillUri,
31+
bool outlineOnly,
32+
IncrementalSerializer incrementalSerializer]) {
2733
return new IncrementalCompiler(
2834
new CompilerContext(
2935
new ProcessedOptions(options: options, inputs: [entryPoint])),
3036
initializeFromDillUri,
31-
outlineOnly);
37+
outlineOnly,
38+
incrementalSerializer);
3239
}
3340

3441
/// Initialize the incremental compiler from a component.

pkg/front_end/lib/src/api_unstable/vm.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export '../api_prototype/file_system.dart'
1717
export '../api_prototype/front_end.dart' show CompilerResult;
1818

1919
export '../api_prototype/incremental_kernel_generator.dart'
20-
show IncrementalKernelGenerator, isLegalIdentifier;
20+
show IncrementalKernelGenerator, IncrementalSerializer, isLegalIdentifier;
2121

2222
export '../api_prototype/kernel_generator.dart'
2323
show kernelForModule, kernelForProgram;

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

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import 'package:kernel/binary/ast_from_binary.dart'
1414
BinaryBuilderWithMetadata,
1515
CanonicalNameError,
1616
CanonicalNameSdkError,
17-
InvalidKernelVersionError;
17+
InvalidKernelVersionError,
18+
SubComponentView;
1819

1920
import 'package:kernel/class_hierarchy.dart'
2021
show ClassHierarchy, ClosedWorldClassHierarchy;
@@ -63,6 +64,8 @@ import 'dill/dill_library_builder.dart' show DillLibraryBuilder;
6364

6465
import 'dill/dill_target.dart' show DillTarget;
6566

67+
import 'incremental_serializer.dart' show IncrementalSerializer;
68+
6669
import 'util/error_reporter_file_copier.dart' show saveAsGzip;
6770

6871
import 'fasta_codes.dart'
@@ -108,13 +111,15 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
108111
final Uri initializeFromDillUri;
109112
final Component componentToInitializeFrom;
110113
bool initializedFromDill = false;
114+
bool initializedIncrementalSerializer = false;
111115
Uri previousPackagesUri;
112116
Map<String, Uri> previousPackagesMap;
113117
Map<String, Uri> currentPackagesMap;
114118
bool hasToCheckPackageUris = false;
115119
Map<Uri, List<DiagnosticMessageFromJson>> remainingComponentProblems =
116120
new Map<Uri, List<DiagnosticMessageFromJson>>();
117121
List<Component> modulesToLoad;
122+
IncrementalSerializer incrementalSerializer;
118123

119124
static final Uri debugExprUri =
120125
new Uri(scheme: "org-dartlang-debug", path: "synthetic_debug_expression");
@@ -123,16 +128,20 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
123128

124129
IncrementalCompiler.fromComponent(
125130
this.context, Component this.componentToInitializeFrom,
126-
[bool outlineOnly])
131+
[bool outlineOnly, IncrementalSerializer incrementalSerializer])
127132
: ticker = context.options.ticker,
128133
initializeFromDillUri = null,
129-
this.outlineOnly = outlineOnly ?? false;
134+
this.outlineOnly = outlineOnly ?? false,
135+
this.incrementalSerializer = incrementalSerializer;
130136

131137
IncrementalCompiler(this.context,
132-
[this.initializeFromDillUri, bool outlineOnly])
138+
[this.initializeFromDillUri,
139+
bool outlineOnly,
140+
IncrementalSerializer incrementalSerializer])
133141
: ticker = context.options.ticker,
134142
componentToInitializeFrom = null,
135-
this.outlineOnly = outlineOnly ?? false;
143+
this.outlineOnly = outlineOnly ?? false,
144+
this.incrementalSerializer = incrementalSerializer;
136145

137146
@override
138147
Future<Component> computeDelta(
@@ -240,7 +249,9 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
240249

241250
bool removedDillBuilders = false;
242251
for (LibraryBuilder builder in notReusedLibraries) {
252+
// TODO(jensj): What about parts in uriToSource?
243253
CompilerContext.current.uriToSource.remove(builder.fileUri);
254+
incrementalSerializer?.invalidate(builder.fileUri);
244255

245256
LibraryBuilder dillBuilder =
246257
dillLoadedData.loader.builders.remove(builder.uri);
@@ -703,6 +714,9 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
703714
uriToSource.remove(uri);
704715
userBuilders?.remove(uri);
705716
removeLibraryFromRemainingComponentProblems(lib, uriTranslator);
717+
718+
// Technically this isn't necessary as the uri is not a package-uri.
719+
incrementalSerializer?.invalidate(builder.fileUri);
706720
}
707721
}
708722
hierarchy?.applyTreeChanges(removedLibraries, const []);
@@ -755,9 +769,14 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
755769

756770
// We're going to output all we read here so lazy loading it
757771
// doesn't make sense.
758-
new BinaryBuilderWithMetadata(initializationBytes,
772+
List<SubComponentView> views = new BinaryBuilderWithMetadata(
773+
initializationBytes,
759774
disableLazyReading: true)
760-
.readComponent(data.component, checkCanonicalNames: true);
775+
.readComponent(data.component,
776+
checkCanonicalNames: true, createView: true);
777+
initializedIncrementalSerializer =
778+
incrementalSerializer?.initialize(initializationBytes, views) ??
779+
false;
761780

762781
// Check the any package-urls still point to the same file
763782
// (e.g. the package still exists and hasn't been updated).

0 commit comments

Comments
 (0)