Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit ace1d9b

Browse files
jcollins-gcommit-bot@chromium.org
authored andcommitted
Do not repeatedly analyze a full library per part when dartfixing.
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 <[email protected]> Commit-Queue: Janice Collins <[email protected]>
1 parent cc85d28 commit ace1d9b

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

pkg/analysis_server/lib/src/edit/edit_dartfix.dart

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import 'package:analyzer/dart/analysis/results.dart';
1515
import 'package:analyzer/dart/analysis/session.dart';
1616
import 'package:analyzer/file_system/file_system.dart';
1717
import 'package:analyzer/src/generated/engine.dart' show AnalysisOptionsImpl;
18+
import 'package:analyzer/src/generated/source.dart' show SourceKind;
1819

1920
class EditDartFix
2021
with FixCodeProcessor, FixErrorProcessor, FixLintProcessor
@@ -34,7 +35,6 @@ class EditDartFix
3435

3536
Future<Response> compute() async {
3637
final params = EditDartfixParams.fromRequest(request);
37-
3838
// Determine the fixes to be applied
3939
final fixInfo = <DartFixInfo>[];
4040
if (params.includePedanticFixes == true) {
@@ -208,6 +208,8 @@ class EditDartFix
208208
for (String rootPath in contextManager.includedPaths) {
209209
resources.add(resourceProvider.getResource(rootPath));
210210
}
211+
212+
var pathsToProcess = <String>{};
211213
while (resources.isNotEmpty) {
212214
Resource res = resources.removeLast();
213215
if (res is Folder) {
@@ -223,7 +225,38 @@ class EditDartFix
223225
if (!isIncluded(res.path)) {
224226
continue;
225227
}
226-
ResolvedUnitResult result = await server.getResolvedUnit(res.path);
228+
pathsToProcess.add(res.path);
229+
}
230+
231+
var pathsProcessed = <String>{};
232+
for (String path in pathsToProcess) {
233+
if (pathsProcessed.contains(path)) continue;
234+
var driver = server.getAnalysisDriver(path);
235+
switch (await driver.getSourceKind(path)) {
236+
case SourceKind.PART:
237+
// Parts will either be found in a library, below, or if the library
238+
// isn't [isIncluded], will be picked up in the final loop.
239+
continue;
240+
break;
241+
case SourceKind.LIBRARY:
242+
ResolvedLibraryResult result = await driver.getResolvedLibrary(path);
243+
if (result != null) {
244+
for (var unit in result.units) {
245+
if (pathsToProcess.contains(unit.path) &&
246+
!pathsProcessed.contains(unit.path)) {
247+
await process(unit);
248+
pathsProcessed.add(unit.path);
249+
}
250+
}
251+
}
252+
break;
253+
default:
254+
break;
255+
}
256+
}
257+
258+
for (String path in pathsToProcess.difference(pathsProcessed)) {
259+
ResolvedUnitResult result = await server.getResolvedUnit(path);
227260
if (result == null || result.unit == null) {
228261
continue;
229262
}

pkg/analysis_server_client/lib/server.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Server {
2828

2929
/// Replicate all stdout/stderr data from the server process to stdout/stderr,
3030
/// when true.
31-
bool _stdioPassthrough;
31+
final bool _stdioPassthrough;
3232

3333
/// Commands that have been sent to the server but not yet acknowledged,
3434
/// and the [Completer] objects which should be completed

pkg/analyzer/lib/src/dart/error/lint_codes.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ class LintCode extends ErrorCode {
1818
@override
1919
ErrorSeverity get errorSeverity => ErrorSeverity.INFO;
2020

21+
@override
22+
int get hashCode => uniqueName.hashCode;
23+
24+
@override
25+
bool operator ==(other) => uniqueName == other.uniqueName;
26+
2127
@override
2228
ErrorType get type => ErrorType.LINT;
2329

0 commit comments

Comments
 (0)