Skip to content

Commit 0fa8986

Browse files
jakemac53commit-bot@chromium.org
authored andcommitted
Use worker input digests for ddk instead of reading the full file bytes.
Also actually compare the SDK summary digest instead of assuming it doesn't change. Most of this logic is mirroring logic in the bazel_worker.dart file that kernel uses, which eventually we should unify. Change-Id: If33af0d8de0b0a6a17081dcd852dd036c4b34a82 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107184 Auto-Submit: Jake Macdonald <jakemac@google.com> Reviewed-by: Vijay Menon <vsm@google.com> Commit-Queue: Jake Macdonald <jakemac@google.com>
1 parent bc9a6a7 commit 0fa8986

4 files changed

Lines changed: 46 additions & 14 deletions

File tree

pkg/dev_compiler/bin/dartdevc.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,20 @@ class _CompilerWorker extends AsyncWorkerLoop {
5252
var args = _startupArgs.merge(request.arguments);
5353
var output = StringBuffer();
5454
var context = args.reuseResult ? lastResult : null;
55-
lastResult = await runZoned(() => compile(args, previousResult: context),
55+
56+
/// Build a map of uris to digests.
57+
final inputDigests = <Uri, List<int>>{};
58+
for (var input in request.inputs) {
59+
var uri = Uri.parse(input.path);
60+
if (uri.scheme.isEmpty) {
61+
uri = Uri.parse('file://${input.path}');
62+
}
63+
inputDigests[uri] = input.digest;
64+
}
65+
66+
lastResult = await runZoned(
67+
() =>
68+
compile(args, previousResult: context, inputDigests: inputDigests),
5669
zoneSpecification:
5770
ZoneSpecification(print: (self, parent, zone, message) {
5871
output.writeln(message.toString());

pkg/dev_compiler/lib/src/compiler/shared_command.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,15 +400,16 @@ Map placeSourceMap(Map sourceMap, String sourceMapPath,
400400
/// The result may also contain a [previousResult], which can be passed back in
401401
/// for batch/worker executions to attempt to existing state.
402402
Future<CompilerResult> compile(ParsedArguments args,
403-
{CompilerResult previousResult}) {
403+
{CompilerResult previousResult, Map<Uri, List<int>> inputDigests}) {
404404
if (previousResult != null && !args.isBatchOrWorker) {
405405
throw ArgumentError(
406406
'previousResult requires --batch or --bazel_worker mode/');
407407
}
408408
if (args.isKernel) {
409409
return kernel_compiler.compile(args.rest,
410410
compilerState: previousResult?.kernelState,
411-
useIncrementalCompiler: args.useIncrementalCompiler);
411+
useIncrementalCompiler: args.useIncrementalCompiler,
412+
inputDigests: inputDigests);
412413
} else {
413414
var result = analyzer_compiler.compile(args.rest,
414415
compilerState: previousResult?.analyzerState);

pkg/dev_compiler/lib/src/kernel/command.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ const _binaryName = 'dartdevc -k';
3737
/// Returns `true` if the program compiled without any fatal errors.
3838
Future<CompilerResult> compile(List<String> args,
3939
{fe.InitializedCompilerState compilerState,
40-
bool useIncrementalCompiler = false}) async {
40+
bool useIncrementalCompiler = false,
41+
Map<Uri, List<int>> inputDigests}) async {
4142
try {
4243
return await _compile(args,
4344
compilerState: compilerState,
44-
useIncrementalCompiler: useIncrementalCompiler);
45+
useIncrementalCompiler: useIncrementalCompiler,
46+
inputDigests: inputDigests);
4547
} catch (error, stackTrace) {
4648
print('''
4749
We're sorry, you've found a bug in our compiler.
@@ -68,7 +70,8 @@ String _usageMessage(ArgParser ddcArgParser) =>
6870

6971
Future<CompilerResult> _compile(List<String> args,
7072
{fe.InitializedCompilerState compilerState,
71-
bool useIncrementalCompiler = false}) async {
73+
bool useIncrementalCompiler = false,
74+
Map<Uri, List<int>> inputDigests}) async {
7275
// TODO(jmesserly): refactor options to share code with dartdevc CLI.
7376
var argParser = ArgParser(allowTrailingOptions: true)
7477
..addFlag('help',
@@ -253,6 +256,7 @@ Future<CompilerResult> _compile(List<String> args,
253256
sourcePathToUri(packageFile),
254257
sourcePathToUri(librarySpecPath),
255258
summaryModules.keys.toList(),
259+
inputDigests,
256260
DevCompilerTarget(
257261
TargetFlags(trackWidgetCreation: trackWidgetCreation)),
258262
fileSystem: fileSystem,

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

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ Future<InitializedCompilerState> initializeIncrementalCompiler(
131131
Uri packagesFile,
132132
Uri librariesSpecificationUri,
133133
List<Uri> inputSummaries,
134+
Map<Uri, List<int>> workerInputDigests,
134135
Target target,
135136
{FileSystem fileSystem,
136137
Map<ExperimentalFlag, bool> experiments}) async {
@@ -143,12 +144,18 @@ Future<InitializedCompilerState> initializeIncrementalCompiler(
143144

144145
Map<Uri, WorkerInputComponent> workerInputCache =
145146
oldState?.workerInputCache ?? new Map<Uri, WorkerInputComponent>();
147+
var sdkDigest = workerInputDigests[sdkSummary];
148+
if (sdkDigest == null) {
149+
throw new StateError("Expected to get sdk digest at $cachedSdkInput");
150+
}
151+
146152
cachedSdkInput = workerInputCache[sdkSummary];
147153

148154
if (oldState == null ||
149155
oldState.incrementalCompiler == null ||
150156
oldState.options.compileSdk != compileSdk ||
151-
cachedSdkInput == null) {
157+
cachedSdkInput == null ||
158+
!digestsEqual(cachedSdkInput.digest, sdkDigest)) {
152159
// No previous state.
153160
options = new CompilerOptions()
154161
..compileSdk = compileSdk
@@ -166,8 +173,8 @@ Future<InitializedCompilerState> initializeIncrementalCompiler(
166173

167174
processedOpts = new ProcessedOptions(options: options);
168175

169-
cachedSdkInput = new WorkerInputComponent(null /* not compared anyway */,
170-
await processedOpts.loadSdkSummary(null));
176+
cachedSdkInput = new WorkerInputComponent(
177+
sdkDigest, await processedOpts.loadSdkSummary(null));
171178
workerInputCache[sdkSummary] = cachedSdkInput;
172179
incrementalCompiler = new IncrementalCompiler.fromComponent(
173180
new CompilerContext(processedOpts), cachedSdkInput.component);
@@ -207,10 +214,13 @@ Future<InitializedCompilerState> initializeIncrementalCompiler(
207214
for (int i = 0; i < inputSummaries.length; i++) {
208215
Uri inputSummary = inputSummaries[i];
209216
WorkerInputComponent cachedInput = workerInputCache[inputSummary];
217+
var digest = workerInputDigests[inputSummary];
218+
if (digest == null) {
219+
throw new StateError("Expected to get digest for $inputSummary");
220+
}
210221
if (cachedInput == null ||
211222
cachedInput.component.root != nameRoot ||
212-
!digestsEqual(await fileSystem.entityForUri(inputSummary).readAsBytes(),
213-
cachedInput.digest)) {
223+
!digestsEqual(digest, cachedInput.digest)) {
214224
loadFromDillIndexes.add(i);
215225
} else {
216226
// Need to reset cached components so they are usable again.
@@ -226,11 +236,15 @@ Future<InitializedCompilerState> initializeIncrementalCompiler(
226236
for (int i = 0; i < loadFromDillIndexes.length; i++) {
227237
int index = loadFromDillIndexes[i];
228238
Uri summary = inputSummaries[index];
229-
List<int> data = await fileSystem.entityForUri(summary).readAsBytes();
239+
List<int> digest = workerInputDigests[summary];
240+
if (digest == null) {
241+
throw new StateError("Expected to get digest for $summary");
242+
}
243+
var bytes = await fileSystem.entityForUri(summary).readAsBytes();
230244
WorkerInputComponent cachedInput = WorkerInputComponent(
231-
data,
245+
digest,
232246
await compilerState.processedOpts
233-
.loadComponent(data, nameRoot, alwaysCreateNewNamedNodes: true));
247+
.loadComponent(bytes, nameRoot, alwaysCreateNewNamedNodes: true));
234248
workerInputCache[summary] = cachedInput;
235249
doneInputSummaries[index] = cachedInput.component;
236250
}

0 commit comments

Comments
 (0)