Skip to content

Commit 47bc250

Browse files
jensjohaCommit Queue
authored andcommitted
[analyzer] Add benchmark that calls getFixes on an actual error
This CL adds a benchmark for getFixes calls on an actual error case. The time it takes is nowhere near the times we're seeing in http://b/407797012 but it's better than nothing. The benchmark does 5 requests for `getFixes`. The first one is always much slower because it has to "discover files". Comparing old dart releases and CLs https://dart-review.googlesource.com/c/sdk/+/420323 and https://dart-review.googlesource.com/c/sdk/+/421220: 3.7.2 was quite a bit slower than 3.6.2. Both CL 420323 and CL 421220 improve things - both separately and combined. With both we're faster than 3.6.2 for all but the first getFixes call (which has to "discover files"). Details: ``` Comparing 3.5.4 with 3.6.2 no change. Comparing 3.6.2 with 3.7.2 Fixes (1): 16.4789% +/- 8.3240% (0.23 +/- 0.12) (1.39 -> 1.62) Fixes (2): 300.2940% +/- 21.5781% (0.06 +/- 0.00) (0.02 -> 0.08) Fixes (3): 220.0321% +/- 23.8171% (0.05 +/- 0.01) (0.02 -> 0.07) Fixes (4): 89.0472% +/- 86.0948% (0.03 +/- 0.03) (0.04 -> 0.07) Fixes (5): 202.9467% +/- 22.5906% (0.04 +/- 0.00) (0.02 -> 0.07) Comparing 3.7.2 with HEAD-ish without the two CLs Fixes (1): 9.2103% +/- 6.7559% (0.15 +/- 0.11) (1.62 -> 1.77) Fixes (2): -32.2017% +/- 7.2433% (-0.03 +/- 0.01) (0.08 -> 0.06) Fixes (3): -39.1903% +/- 7.4656% (-0.03 +/- 0.01) (0.07 -> 0.04) Fixes (4): -41.5019% +/- 8.2911% (-0.03 +/- 0.01) (0.07 -> 0.04) Fixes (5): -38.7623% +/- 4.4327% (-0.03 +/- 0.00) (0.07 -> 0.04) Comparing HEAD-ish without the two CLs with CL 420323 (cache) only Fixes (1): -5.9976% +/- 4.4944% (-0.11 +/- 0.08) (1.77 -> 1.66) Fixes (4): -39.3839% +/- 13.3201% (-0.02 +/- 0.01) (0.04 -> 0.02) Fixes (5): -49.0495% +/- 4.2557% (-0.02 +/- 0.00) (0.04 -> 0.02) Comparing CL 420323 (cache) only with CL 421220 (element2) only Fixes (2): -63.4332% +/- 42.9828% (-0.02 +/- 0.02) (0.04 -> 0.01) Fixes (3): -79.6318% +/- 17.5009% (-0.04 +/- 0.01) (0.05 -> 0.01) Fixes (4): -68.4995% +/- 11.7414% (-0.02 +/- 0.00) (0.02 -> 0.01) Fixes (5): -54.6697% +/- 11.1116% (-0.01 +/- 0.00) (0.02 -> 0.01) Comparing CL 421220 (element2) only with both Fixes (2): -21.3437% +/- 7.8302% (-0.00 +/- 0.00) (0.01 -> 0.01) Fixes (3): -17.7975% +/- 10.4789% (-0.00 +/- 0.00) (0.01 -> 0.01) Fixes (5): -30.5353% +/- 20.5827% (-0.00 +/- 0.00) (0.01 -> 0.01) ``` Change-Id: I477c7a73c669099e2d7bc9d64000cfb78ced2ea4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/421601 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Jens Johansen <[email protected]>
1 parent 6e8e0f8 commit 47bc250

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

pkg/analysis_server/tool/benchmark_tools/big_chain_benchmark/benchmark_utils.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ $typing
121121
""";
122122
var typingAtOffset = mainFileTypingContent.indexOf(typing) + typing.length;
123123

124+
var typingError = 'getFooBarBaz';
125+
var mainFileTypingErrorContent = """
126+
import '${getFilenameFor(1)}';
127+
128+
void main(List<String> arguments) {
129+
arguments.$typingError();
130+
}
131+
""";
132+
var typingErrorAtOffset =
133+
mainFileTypingErrorContent.indexOf(typingError) + typingError.length;
134+
124135
if (includePlugin) {
125136
String executableToUse = extractDartParamOrDefault(args);
126137
void pubGetIn(String dir) {
@@ -196,6 +207,8 @@ analyzer:
196207
mainFile: FileContentPair(mainFileUri, mainFileContent),
197208
mainFileTypingContent: mainFileTypingContent,
198209
typingAtOffset: typingAtOffset,
210+
mainFileTypingErrorContent: mainFileTypingErrorContent,
211+
typingErrorAtOffset: typingErrorAtOffset,
199212
orderedFileCopies: orderedFileCopies,
200213
numFiles: numFiles,
201214
);
@@ -243,6 +256,8 @@ class RunDetails {
243256
final FileContentPair mainFile;
244257
final String mainFileTypingContent;
245258
final int typingAtOffset;
259+
final String mainFileTypingErrorContent;
260+
final int typingErrorAtOffset;
246261
final List<FileContentPair> orderedFileCopies;
247262
final int numFiles;
248263

@@ -251,6 +266,8 @@ class RunDetails {
251266
required this.mainFile,
252267
required this.mainFileTypingContent,
253268
required this.typingAtOffset,
269+
required this.mainFileTypingErrorContent,
270+
required this.typingErrorAtOffset,
254271
required this.orderedFileCopies,
255272
required this.numFiles,
256273
});
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import '../language_server_benchmark.dart';
6+
import '../legacy_messages.dart';
7+
import '../run_utils.dart';
8+
import 'benchmark_utils.dart';
9+
10+
/// Call getFixes on an actual error, just like IntelliJ would when the cursor
11+
/// is on an error.
12+
Future<void> main(List<String> args) async {
13+
await runHelper(
14+
args,
15+
LegacyGetFixesOnErrorBenchmark.new,
16+
copyData,
17+
extraIterations: getExtraIterations,
18+
runAsLsp: false,
19+
);
20+
}
21+
22+
class LegacyGetFixesOnErrorBenchmark extends DartLanguageServerBenchmark {
23+
@override
24+
final Uri rootUri;
25+
@override
26+
final Uri cacheFolder;
27+
28+
final RunDetails runDetails;
29+
30+
LegacyGetFixesOnErrorBenchmark(
31+
super.args,
32+
this.rootUri,
33+
this.cacheFolder,
34+
this.runDetails,
35+
) : super(useLspProtocol: false);
36+
37+
@override
38+
LaunchFrom get launchFrom => LaunchFrom.Dart;
39+
40+
@override
41+
Future<void> afterInitialization() async {
42+
// The main file is an open tab.
43+
await send(
44+
LegacyMessages.setPriorityFiles(largestIdSeen + 1, [
45+
runDetails.mainFile.uri,
46+
]),
47+
);
48+
49+
// Does this change anything?
50+
await Future.delayed(const Duration(milliseconds: 100));
51+
52+
var isNowAnalyzingFuture = waitUntilIsAnalyzingChanges();
53+
54+
// The user typed, but it's an error.
55+
await send(
56+
LegacyMessages.updateContent(
57+
largestIdSeen + 1,
58+
runDetails.mainFile.uri,
59+
runDetails.mainFileTypingErrorContent,
60+
),
61+
);
62+
63+
bool isAnalyzing = await isNowAnalyzingFuture;
64+
if (isAnalyzing == false) throw 'Expected true.';
65+
await waitWhileAnalyzing();
66+
67+
// It's done analyzing: Ask for fixes on the error.
68+
for (int i = 0; i < 5; i++) {
69+
Stopwatch stopwatch = Stopwatch()..start();
70+
var result =
71+
await (await send(
72+
LegacyMessages.getFixes(
73+
largestIdSeen + 1,
74+
runDetails.mainFile.uri,
75+
runDetails.typingErrorAtOffset,
76+
),
77+
))!.completer.future;
78+
stopwatch.stop();
79+
var error = result['result']['fixes'].first['error']['type'];
80+
if (error != 'COMPILE_TIME_ERROR') throw 'Expected COMPILE_TIME_ERROR';
81+
durationInfo.add(DurationInfo('Fixes (${i + 1})', stopwatch.elapsed));
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)