Skip to content

Commit c64cd5f

Browse files
scheglovCommit Queue
authored and
Commit Queue
committed
Macro. Add more operation performance details.
Bug: #55784 Change-Id: Ibe83b4eee8bbf47ee79193244f9233cdb1b6aece Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373161 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Phil Quitslund <[email protected]>
1 parent aea99e7 commit c64cd5f

File tree

7 files changed

+73
-33
lines changed

7 files changed

+73
-33
lines changed

pkg/analyzer/lib/src/dart/analysis/driver.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1593,7 +1593,6 @@ class AnalysisDriver {
15931593
);
15941594

15951595
_fsState = FileSystemState(
1596-
_logger,
15971596
_byteStore,
15981597
_resourceProvider,
15991598
name,

pkg/analyzer/lib/src/dart/analysis/file_state.dart

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import 'package:analyzer/src/dart/analysis/defined_names.dart';
2222
import 'package:analyzer/src/dart/analysis/feature_set_provider.dart';
2323
import 'package:analyzer/src/dart/analysis/file_content_cache.dart';
2424
import 'package:analyzer/src/dart/analysis/library_graph.dart';
25-
import 'package:analyzer/src/dart/analysis/performance_logger.dart';
2625
import 'package:analyzer/src/dart/analysis/referenced_names.dart';
2726
import 'package:analyzer/src/dart/analysis/unlinked_api_signature.dart';
2827
import 'package:analyzer/src/dart/analysis/unlinked_data.dart';
@@ -779,11 +778,17 @@ class FileState {
779778
performance: performance,
780779
).unit;
781780

782-
return _fsState._logger.run('Create unlinked for $path', () {
783-
var unlinkedUnit = serializeAstUnlinked2(
784-
unit,
785-
exists: exists,
786-
isDartCore: uriStr == 'dart:core',
781+
return performance.run('compute', (performance) {
782+
var unlinkedUnit = performance.run(
783+
'serializeAstUnlinked2',
784+
(performance) {
785+
return serializeAstUnlinked2(
786+
unit,
787+
exists: exists,
788+
isDartCore: uriStr == 'dart:core',
789+
performance: performance,
790+
);
791+
},
787792
);
788793
var definedNames = computeDefinedNames(unit);
789794
var referencedNames = computeReferencedNames(unit);
@@ -914,6 +919,7 @@ class FileState {
914919
CompilationUnit unit, {
915920
required bool exists,
916921
required bool isDartCore,
922+
required OperationPerformanceImpl performance,
917923
}) {
918924
UnlinkedLibraryDirective? libraryDirective;
919925
UnlinkedLibraryAugmentationDirective? libraryAugmentationDirective;
@@ -1054,12 +1060,15 @@ class FileState {
10541060
}
10551061
}
10561062

1057-
var apiSignature = ApiSignature();
1058-
apiSignature.addBytes(computeUnlinkedApiSignature(unit));
1059-
apiSignature.addBool(exists);
1063+
var apiSignature = performance.run('apiSignature', (performance) {
1064+
var signatureBuilder = ApiSignature();
1065+
signatureBuilder.addBytes(computeUnlinkedApiSignature(unit));
1066+
signatureBuilder.addBool(exists);
1067+
return signatureBuilder.toByteList();
1068+
});
10601069

10611070
return UnlinkedUnit(
1062-
apiSignature: apiSignature.toByteList(),
1071+
apiSignature: apiSignature,
10631072
augmentations: augmentations.toFixedList(),
10641073
exports: exports.toFixedList(),
10651074
imports: imports.toFixedList(),
@@ -1183,7 +1192,6 @@ class FileStateTestView {
11831192

11841193
/// Information about known file system state.
11851194
class FileSystemState {
1186-
final PerformanceLog _logger;
11871195
final ResourceProvider resourceProvider;
11881196
final String contextName;
11891197
final ByteStore _byteStore;
@@ -1244,14 +1252,21 @@ class FileSystemState {
12441252
/// Used for looking up options to associate with created file states.
12451253
final AnalysisOptionsMap _analysisOptionsMap;
12461254

1255+
/// The default performance for [_newFile].
1256+
///
1257+
/// [_newFile] does expensive work, so it is important to see which
1258+
/// operations it does, and how long they take. But it can be reached
1259+
/// through getters, which we would like to keep getters. So, instead we
1260+
/// store here the instance to attach [_newFile] operations.
1261+
OperationPerformanceImpl? newFileOperationPerformance;
1262+
12471263
/// We cache results of parsing [FileState]s because they might be useful
12481264
/// in the process of a single analysis operation. But after that, even
12491265
/// if these results are still valid, they are often never used again. So,
12501266
/// currently we clear the cache after each operation.
12511267
ParsedFileStateCache parsedFileStateCache = ParsedFileStateCache();
12521268

12531269
FileSystemState(
1254-
this._logger,
12551270
this._byteStore,
12561271
this.resourceProvider,
12571272
this.contextName,
@@ -1577,6 +1592,7 @@ class FileSystemState {
15771592
knownFiles.add(file);
15781593
fileStamp++;
15791594

1595+
performance ??= newFileOperationPerformance;
15801596
performance ??= OperationPerformanceImpl('<root>');
15811597
performance.run('fileState.refresh', (performance) {
15821598
file.refresh(

pkg/analyzer/lib/src/dart/analysis/library_context.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,14 @@ class LibraryContext {
285285
}
286286

287287
await logger.runAsync('Prepare linked bundles', () async {
288-
var libraryCycle = targetLibrary.libraryCycle;
288+
var libraryCycle = performance.run('libraryCycle', (performance) {
289+
fileSystemState.newFileOperationPerformance = performance;
290+
try {
291+
return targetLibrary.libraryCycle;
292+
} finally {
293+
fileSystemState.newFileOperationPerformance = null;
294+
}
295+
});
289296
await loadBundle(libraryCycle);
290297
logger.writeln(
291298
'[librariesTotal: $librariesTotal]'

pkg/analyzer/lib/src/dart/micro/resolve_file.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,6 @@ class FileResolver {
736736
);
737737

738738
fsState = FileSystemState(
739-
logger,
740739
byteStore,
741740
resourceProvider,
742741
'contextName',

pkg/analyzer/lib/src/summary2/library_builder.dart

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,21 +1276,24 @@ class LibraryBuilder with MacroApplicationsContainer {
12761276
}
12771277
}
12781278

1279-
static void build(
1280-
Linker linker,
1281-
LibraryFileKind inputLibrary,
1282-
MacroResultInput? inputMacroResult,
1283-
) {
1279+
static void build({
1280+
required Linker linker,
1281+
required LibraryFileKind inputLibrary,
1282+
required MacroResultInput? inputMacroResult,
1283+
required OperationPerformanceImpl performance,
1284+
}) {
12841285
var elementFactory = linker.elementFactory;
12851286
var rootReference = linker.rootReference;
12861287

12871288
var libraryFile = inputLibrary.file;
12881289
var libraryUriStr = libraryFile.uriStr;
12891290
var libraryReference = rootReference.getChild(libraryUriStr);
12901291

1291-
var libraryUnitNode = libraryFile.parse(
1292-
performance: OperationPerformanceImpl('<root>'),
1293-
);
1292+
var libraryUnitNode = performance.run('libraryFile', (performance) {
1293+
return libraryFile.parse(
1294+
performance: performance,
1295+
);
1296+
});
12941297

12951298
var name = '';
12961299
var nameOffset = -1;

pkg/analyzer/lib/src/summary2/link.dart

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,29 @@ class Linker {
107107
required List<LibraryFileKind> inputLibraries,
108108
required Map<LibraryFileKind, MacroResultInput> inputMacroResults,
109109
}) async {
110-
for (var inputLibrary in inputLibraries) {
111-
var inputMacroResult = inputMacroResults[inputLibrary];
112-
LibraryBuilder.build(this, inputLibrary, inputMacroResult);
113-
}
110+
performance.run('LibraryBuilder.build', (performance) {
111+
for (var inputLibrary in inputLibraries) {
112+
var inputMacroResult = inputMacroResults[inputLibrary];
113+
LibraryBuilder.build(
114+
linker: this,
115+
inputLibrary: inputLibrary,
116+
inputMacroResult: inputMacroResult,
117+
performance: performance,
118+
);
119+
}
120+
});
114121

115-
await _buildOutlines(
116-
performance: performance,
117-
);
122+
await performance.runAsync('buildOutlines', (performance) async {
123+
await _buildOutlines(
124+
performance: performance,
125+
);
126+
});
118127

119-
_writeLibraries();
128+
performance.run('writeLibraries', (performance) {
129+
_writeLibraries(
130+
performance: performance,
131+
);
132+
});
120133
}
121134

122135
void _buildClassSyntheticConstructors() {
@@ -462,7 +475,9 @@ class Linker {
462475
}
463476
}
464477

465-
void _writeLibraries() {
478+
void _writeLibraries({
479+
required OperationPerformanceImpl performance,
480+
}) {
466481
var bundleWriter = BundleWriter(
467482
elementFactory.dynamicRef,
468483
);
@@ -473,6 +488,8 @@ class Linker {
473488

474489
var writeWriterResult = bundleWriter.finish();
475490
resolutionBytes = writeWriterResult.resolutionBytes;
491+
492+
performance.getDataInt('length').add(resolutionBytes.length);
476493
}
477494
}
478495

pkg/analyzer/test/src/dart/analysis/file_state_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5833,7 +5833,6 @@ class FileSystemStateTest with ResourceProviderMixin {
58335833
packages: Packages.empty,
58345834
);
58355835
fileSystemState = FileSystemState(
5836-
logger,
58375836
byteStore,
58385837
resourceProvider,
58395838
'contextName',

0 commit comments

Comments
 (0)