Skip to content

Commit bd103eb

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Store unlinked data with unlinked salt.
Before this change we used the whole AnalysisOptions.signature as salt. This means that if two packages have different set of lints, they have different options signatures, and so we have to parse and compute unlinked data for SDK and all shared packages separately. But unlinked data depends only on very small set of options, practically only on parser options. This improves performance on workspaces with many modules and empty cache: Before: <= --- Analyzing in 36122 ms. <= Computed implemented in: 50138 ms. <= --- Analyzing in 47905 ms. <= Computed implemented in: 55339 ms. <= --- Analyzing in 45141 ms. <= Computed implemented in: 60169 ms. After: <= --- Analyzing in 27957 ms. <= Computed implemented in: 11645 ms. <= --- Analyzing in 21378 ms. <= Computed implemented in: 9439 ms. <= --- Analyzing in 21719 ms. <= Computed implemented in: 10546 ms. Here "computed implemented" is computing subtypes of classes in the open file - it required unlinked data for all files in all available packages. It also helps for full cache: analysis: 6300 vs. 5700 ms. implemented: 5700 vs. 3700 ms. [email protected], [email protected] Change-Id: I10dbc6d062617466ad5f35ae77bd1e58a6bb606c Reviewed-on: https://dart-review.googlesource.com/75128 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent c5d77d1 commit bd103eb

File tree

7 files changed

+78
-23
lines changed

7 files changed

+78
-23
lines changed

pkg/analysis_server/test/src/plugin/plugin_watcher_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class TestDriver implements AnalysisDriver {
142142
resourceProvider,
143143
sourceFactory,
144144
new AnalysisOptionsImpl(),
145+
new Uint32List(0),
145146
new Uint32List(0));
146147
currentSession = new AnalysisSessionImpl(this);
147148
}

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

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import 'package:analyzer/src/generated/engine.dart'
3232
AnalysisContext,
3333
AnalysisEngine,
3434
AnalysisOptions,
35+
AnalysisOptionsImpl,
3536
PerformanceStatistics;
3637
import 'package:analyzer/src/generated/resolver.dart';
3738
import 'package:analyzer/src/generated/source.dart';
@@ -92,7 +93,7 @@ class AnalysisDriver implements AnalysisDriverGeneric {
9293
/**
9394
* The version of data format, should be incremented on every format change.
9495
*/
95-
static const int DATA_VERSION = 66;
96+
static const int DATA_VERSION = 67;
9697

9798
/**
9899
* The number of exception contexts allowed to write. Once this field is
@@ -139,7 +140,7 @@ class AnalysisDriver implements AnalysisDriverGeneric {
139140
/**
140141
* The analysis options to analyze with.
141142
*/
142-
AnalysisOptions _analysisOptions;
143+
AnalysisOptionsImpl _analysisOptions;
143144

144145
/**
145146
* The optional SDK bundle, used when the client cannot read SDK files.
@@ -163,9 +164,16 @@ class AnalysisDriver implements AnalysisDriverGeneric {
163164
final ContextRoot contextRoot;
164165

165166
/**
166-
* The salt to mix into all hashes used as keys for serialized data.
167+
* The salt to mix into all hashes used as keys for unlinked data.
167168
*/
168-
final Uint32List _salt = new Uint32List(1 + AnalysisOptions.signatureLength);
169+
final Uint32List _unlinkedSalt =
170+
new Uint32List(1 + AnalysisOptionsImpl.unlinkedSignatureLength);
171+
172+
/**
173+
* The salt to mix into all hashes used as keys for linked data.
174+
*/
175+
final Uint32List _linkedSalt =
176+
new Uint32List(1 + AnalysisOptions.signatureLength);
169177

170178
/**
171179
* The set of priority files, that should be analyzed sooner.
@@ -841,7 +849,7 @@ class AnalysisDriver implements AnalysisDriverGeneric {
841849
_throwIfNotAbsolutePath(path);
842850
var file = fsState.getFileForPath(path);
843851
ApiSignature signature = new ApiSignature();
844-
signature.addUint32List(_salt);
852+
signature.addUint32List(_linkedSalt);
845853
signature.addString(file.transitiveSignature);
846854
return signature;
847855
}
@@ -1338,8 +1346,15 @@ class AnalysisDriver implements AnalysisDriverGeneric {
13381346
*/
13391347
void _createFileTracker() {
13401348
_fillSalt();
1341-
_fsState = new FileSystemState(_logger, _byteStore, _contentOverlay,
1342-
_resourceProvider, sourceFactory, analysisOptions, _salt,
1349+
_fsState = new FileSystemState(
1350+
_logger,
1351+
_byteStore,
1352+
_contentOverlay,
1353+
_resourceProvider,
1354+
sourceFactory,
1355+
analysisOptions,
1356+
_unlinkedSalt,
1357+
_linkedSalt,
13431358
externalSummaries: _externalSummaries,
13441359
parseExceptionHandler: _storeExceptionContextDuringParsing);
13451360
_fileTracker = new FileTracker(_logger, _fsState, _changeHook);
@@ -1380,15 +1395,14 @@ class AnalysisDriver implements AnalysisDriverGeneric {
13801395
}
13811396

13821397
/**
1383-
* Fill [_salt] with data.
1398+
* Fill [_unlinkedSalt] and [_linkedSalt] with data.
13841399
*/
13851400
void _fillSalt() {
1386-
_salt[0] = DATA_VERSION;
1387-
List<int> crossContextOptions = _analysisOptions.signature;
1388-
assert(crossContextOptions.length == AnalysisOptions.signatureLength);
1389-
for (int i = 0; i < crossContextOptions.length; i++) {
1390-
_salt[i + 1] = crossContextOptions[i];
1391-
}
1401+
_unlinkedSalt[0] = DATA_VERSION;
1402+
_unlinkedSalt.setAll(1, _analysisOptions.unlinkedSignature);
1403+
1404+
_linkedSalt[0] = DATA_VERSION;
1405+
_linkedSalt.setAll(1, _analysisOptions.signature);
13921406
}
13931407

13941408
/**
@@ -1458,7 +1472,7 @@ class AnalysisDriver implements AnalysisDriverGeneric {
14581472
*/
14591473
String _getResolvedUnitSignature(FileState library, FileState file) {
14601474
ApiSignature signature = new ApiSignature();
1461-
signature.addUint32List(_salt);
1475+
signature.addUint32List(_linkedSalt);
14621476
signature.addString(library.transitiveSignature);
14631477
signature.addString(file.contentHash);
14641478
return signature.toHex();

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ class FileState {
356356
String get transitiveSignature {
357357
if (_transitiveSignature == null) {
358358
ApiSignature signature = new ApiSignature();
359-
signature.addUint32List(_fsState._salt);
359+
signature.addUint32List(_fsState._linkedSalt);
360360
signature.addInt(transitiveFiles.length);
361361
transitiveFiles
362362
.map((file) => file.apiSignature)
@@ -424,7 +424,7 @@ class FileState {
424424
String unlinkedKey;
425425
{
426426
var signature = new ApiSignature();
427-
signature.addUint32List(_fsState._salt);
427+
signature.addUint32List(_fsState._unlinkedSalt);
428428
signature.addString(_contentHash);
429429

430430
var signatureHex = signature.toHex();
@@ -707,7 +707,8 @@ class FileSystemState {
707707
final FileContentOverlay _contentOverlay;
708708
final SourceFactory _sourceFactory;
709709
final AnalysisOptions _analysisOptions;
710-
final Uint32List _salt;
710+
final Uint32List _unlinkedSalt;
711+
final Uint32List _linkedSalt;
711712

712713
/**
713714
* The optional store with externally provided unlinked and corresponding
@@ -789,7 +790,8 @@ class FileSystemState {
789790
this._resourceProvider,
790791
this._sourceFactory,
791792
this._analysisOptions,
792-
this._salt, {
793+
this._unlinkedSalt,
794+
this._linkedSalt, {
793795
this.externalSummaries,
794796
this.parseExceptionHandler,
795797
}) {

pkg/analyzer/lib/src/generated/engine.dart

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,7 @@ class AnalysisNotScheduledError implements Exception {}
11361136
*/
11371137
abstract class AnalysisOptions {
11381138
/**
1139-
* The length of the list returned by [encodeCrossContextOptions].
1139+
* The length of the list returned by [signature].
11401140
*/
11411141
static const int signatureLength = 4;
11421142

@@ -1376,13 +1376,23 @@ class AnalysisOptionsImpl implements AnalysisOptions {
13761376
*/
13771377
static const List<String> NONNULLABLE_TYPES = const <String>[];
13781378

1379+
/**
1380+
* The length of the list returned by [unlinkedSignature].
1381+
*/
1382+
static const int unlinkedSignatureLength = 4;
1383+
13791384
/**
13801385
* A predicate indicating whether analysis is to parse and analyze function
13811386
* bodies.
13821387
*/
13831388
AnalyzeFunctionBodiesPredicate _analyzeFunctionBodiesPredicate =
13841389
_analyzeAllFunctionBodies;
13851390

1391+
/**
1392+
* The cached [unlinkedSignature].
1393+
*/
1394+
Uint32List _unlinkedSignature;
1395+
13861396
/**
13871397
* The cached [signature].
13881398
*/
@@ -1705,6 +1715,26 @@ class AnalysisOptionsImpl implements AnalysisOptions {
17051715
"The strongMode field is deprecated, and shouldn't be assigned to")
17061716
set strongMode(bool value) {}
17071717

1718+
/**
1719+
* Return the opaque signature of the options that affect unlinked data.
1720+
*
1721+
* The length of the list is guaranteed to equal [unlinkedSignatureLength].
1722+
*/
1723+
Uint32List get unlinkedSignature {
1724+
if (_unlinkedSignature == null) {
1725+
ApiSignature buffer = new ApiSignature();
1726+
1727+
// Append boolean flags.
1728+
buffer.addBool(enableLazyAssignmentOperators);
1729+
buffer.addBool(useFastaParser);
1730+
1731+
// Hash and convert to Uint32List.
1732+
List<int> bytes = buffer.toByteList();
1733+
_unlinkedSignature = new Uint8List.fromList(bytes).buffer.asUint32List();
1734+
}
1735+
return _unlinkedSignature;
1736+
}
1737+
17081738
@override
17091739
void resetToDefaults() {
17101740
declarationCasts = true;

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,15 @@ class FileSystemStateTest {
5858
new ResourceUriResolver(provider)
5959
], null, provider);
6060
AnalysisOptions analysisOptions = new AnalysisOptionsImpl();
61-
fileSystemState = new FileSystemState(logger, byteStore, contentOverlay,
62-
provider, sourceFactory, analysisOptions, new Uint32List(0));
61+
fileSystemState = new FileSystemState(
62+
logger,
63+
byteStore,
64+
contentOverlay,
65+
provider,
66+
sourceFactory,
67+
analysisOptions,
68+
new Uint32List(0),
69+
new Uint32List(0));
6370
}
6471

6572
test_definedClassMemberNames() {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class UnitApiSignatureTest extends Object with ResourceProviderMixin {
7272
resourceProvider,
7373
sourceFactory,
7474
new AnalysisOptionsImpl(),
75+
new Uint32List(0),
7576
new Uint32List(0));
7677
}
7778

pkg/analyzer_cli/lib/src/build_mode.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ class BuildMode extends Object with HasContextMixin {
425425
new FileContentOverlay(),
426426
null,
427427
sourceFactory,
428-
analysisOptions,
428+
analysisOptions as AnalysisOptionsImpl,
429429
externalSummaries: summaryDataStore);
430430
analysisDriver.declaredVariables =
431431
new DeclaredVariables.fromMap(options.definedVariables);

0 commit comments

Comments
 (0)