Skip to content

Commit

Permalink
Do not repeatedly analyze a full library per part when dartfixing.
Browse files Browse the repository at this point in the history
Migration performance improves 10x on web_ui with this CL.
Also fixes a heisenbug in the linter code where identical uniqueNames
for LintCodes could wind up in objects that compare differently.

Bug: dart-lang/sdk#40915
Change-Id: Iddddfd7659f4bc724ddf21ebae41750a0ee51e74
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138940
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Janice Collins <jcollins@google.com>
  • Loading branch information
jcollins-g authored and commit-bot@chromium.org committed Mar 10, 2020
1 parent cc85d28 commit ace1d9b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
37 changes: 35 additions & 2 deletions pkg/analysis_server/lib/src/edit/edit_dartfix.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/analysis/session.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/generated/engine.dart' show AnalysisOptionsImpl;
import 'package:analyzer/src/generated/source.dart' show SourceKind;

class EditDartFix
with FixCodeProcessor, FixErrorProcessor, FixLintProcessor
Expand All @@ -34,7 +35,6 @@ class EditDartFix

Future<Response> compute() async {
final params = EditDartfixParams.fromRequest(request);

// Determine the fixes to be applied
final fixInfo = <DartFixInfo>[];
if (params.includePedanticFixes == true) {
Expand Down Expand Up @@ -208,6 +208,8 @@ class EditDartFix
for (String rootPath in contextManager.includedPaths) {
resources.add(resourceProvider.getResource(rootPath));
}

var pathsToProcess = <String>{};
while (resources.isNotEmpty) {
Resource res = resources.removeLast();
if (res is Folder) {
Expand All @@ -223,7 +225,38 @@ class EditDartFix
if (!isIncluded(res.path)) {
continue;
}
ResolvedUnitResult result = await server.getResolvedUnit(res.path);
pathsToProcess.add(res.path);
}

var pathsProcessed = <String>{};
for (String path in pathsToProcess) {
if (pathsProcessed.contains(path)) continue;
var driver = server.getAnalysisDriver(path);
switch (await driver.getSourceKind(path)) {
case SourceKind.PART:
// Parts will either be found in a library, below, or if the library
// isn't [isIncluded], will be picked up in the final loop.
continue;
break;
case SourceKind.LIBRARY:
ResolvedLibraryResult result = await driver.getResolvedLibrary(path);
if (result != null) {
for (var unit in result.units) {
if (pathsToProcess.contains(unit.path) &&
!pathsProcessed.contains(unit.path)) {
await process(unit);
pathsProcessed.add(unit.path);
}
}
}
break;
default:
break;
}
}

for (String path in pathsToProcess.difference(pathsProcessed)) {
ResolvedUnitResult result = await server.getResolvedUnit(path);
if (result == null || result.unit == null) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/analysis_server_client/lib/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Server {

/// Replicate all stdout/stderr data from the server process to stdout/stderr,
/// when true.
bool _stdioPassthrough;
final bool _stdioPassthrough;

/// Commands that have been sent to the server but not yet acknowledged,
/// and the [Completer] objects which should be completed
Expand Down
6 changes: 6 additions & 0 deletions pkg/analyzer/lib/src/dart/error/lint_codes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ class LintCode extends ErrorCode {
@override
ErrorSeverity get errorSeverity => ErrorSeverity.INFO;

@override
int get hashCode => uniqueName.hashCode;

@override
bool operator ==(other) => uniqueName == other.uniqueName;

@override
ErrorType get type => ErrorType.LINT;

Expand Down

0 comments on commit ace1d9b

Please sign in to comment.