Skip to content

Commit ad3e20a

Browse files
jensjohaCommit Queue
authored andcommitted
[analyzer] Skip repeated equal yaml edit calculations
For `lsp_many_prefer_single_quotes_violations_benchmark.dart --sizes=3200`: Before: Initial analysis: 0.115672 First code action call: 2.577159 Subsequent action call 1: 2.154116 Subsequent action call 2: 2.321183 Select all code action call: 6.890875 After: Initial analysis: 0.114040 First code action call: 2.585689 Subsequent action call 1: 2.099005 Subsequent action call 2: 2.229051 Select all code action call: 4.695931 Change-Id: I3f20b9fe7c0a5cf6d9f4e5ca74193fc1f0668af2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/427221 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Jens Johansen <[email protected]>
1 parent 119116f commit ad3e20a

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

pkg/analysis_server_plugin/lib/src/correction/fix_processor.dart

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:analysis_server_plugin/edit/fix/dart_fix_context.dart';
77
import 'package:analysis_server_plugin/edit/fix/fix.dart';
88
import 'package:analysis_server_plugin/src/correction/fix_generators.dart';
99
import 'package:analysis_server_plugin/src/correction/fix_in_file_processor.dart';
10+
import 'package:analysis_server_plugin/src/correction/ignore_diagnostic.dart';
1011
import 'package:analysis_server_plugin/src/correction/performance.dart';
1112
import 'package:analyzer/src/error/codes.dart';
1213
import 'package:analyzer/src/generated/java_core.dart';
@@ -17,7 +18,10 @@ Future<List<Fix>> computeFixes(DartFixContext context,
1718
{FixPerformance? performance,
1819
Set<String>? skipAlreadyCalculatedIfNonNull}) async {
1920
return [
20-
...await FixProcessor(context, performance: performance).compute(),
21+
...await FixProcessor(context,
22+
performance: performance,
23+
alreadyCalculated: skipAlreadyCalculatedIfNonNull)
24+
.compute(),
2125
...await FixInFileProcessor(context,
2226
alreadyCalculated: skipAlreadyCalculatedIfNonNull)
2327
.compute(),
@@ -36,10 +40,21 @@ class FixProcessor {
3640
final FixPerformance? _performance;
3741
final Stopwatch _timer = Stopwatch();
3842

43+
final Set<String>? alreadyCalculated;
44+
3945
final List<Fix> _fixes = <Fix>[];
4046

41-
FixProcessor(this._fixContext, {FixPerformance? performance})
42-
: _performance = performance;
47+
/// If passing [alreadyCalculated] for calculations where we know the output
48+
/// will be the same, a result will only be calculated if one hasn't been
49+
/// calculated already (for a similar situation). If calculating the Set will
50+
/// be ammended with this information.
51+
/// If not passing [alreadyCalculated] the calculation will always be
52+
/// performed.
53+
FixProcessor(
54+
this._fixContext, {
55+
FixPerformance? performance,
56+
this.alreadyCalculated,
57+
}) : _performance = performance;
4358

4459
Future<List<Fix>> compute() async {
4560
_timer.start();
@@ -137,7 +152,17 @@ class FixProcessor {
137152
errorCode is HintCode ||
138153
errorCode is WarningCode) {
139154
for (var generator in registeredFixGenerators.ignoreProducerGenerators) {
140-
await compute(generator(context: context));
155+
var producer = generator(context: context);
156+
if (producer.fixKind == ignoreErrorAnalysisFileKind) {
157+
if (alreadyCalculated?.add('${generator.hashCode}|'
158+
'${ignoreErrorAnalysisFileKind.id}|'
159+
'${error.errorCode.name}') ==
160+
false) {
161+
// We did this before and was asked to not do it again. Skip.
162+
continue;
163+
}
164+
}
165+
await compute(producer);
141166
}
142167
}
143168
}

0 commit comments

Comments
 (0)