Update completion benchmarks to the new protocol.

Stop subscribing for AVAILABLE_SUGGESTION_SETS.

Change-Id: I93aa0f1227d766346a115327d1f79e95739a2435
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/240761
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analysis_server/benchmark/perf/benchmarks_impl.dart b/pkg/analysis_server/benchmark/perf/benchmarks_impl.dart
index f0d8533..d394ef0 100644
--- a/pkg/analysis_server/benchmark/perf/benchmarks_impl.dart
+++ b/pkg/analysis_server/benchmark/perf/benchmarks_impl.dart
@@ -76,7 +76,7 @@
     var stopwatch = Stopwatch()..start();
 
     Future _complete(int offset) async {
-      await test.complete(filePath, offset);
+      await test.complete(filePath, offset, isWarmUp: false);
       completionCount++;
     }
 
diff --git a/pkg/analysis_server/benchmark/perf/flutter_completion_benchmark.dart b/pkg/analysis_server/benchmark/perf/flutter_completion_benchmark.dart
index a874443..a2fe460 100644
--- a/pkg/analysis_server/benchmark/perf/flutter_completion_benchmark.dart
+++ b/pkg/analysis_server/benchmark/perf/flutter_completion_benchmark.dart
@@ -144,10 +144,6 @@
       // about all these libraries. We change a method body, so the API
       // signature is the same, and we are able to reload these libraries
       // from bytes. But this still costs something.
-      // There is also a spill-over from the previous test - we send a lot
-      // (about 5MB) of available declarations after each change. This makes
-      // completion response times very large.
-      // TODO(scheglov) Remove the previous sentence when improved.
       // Total number of suggestions: 3429.
       // Filtered to: 133.
       // Long name: completion-mediumLibraryCycle-mediumFile-smallBody
@@ -219,7 +215,7 @@
 
     await test.openFile(filePath, fileContent);
 
-    Future<void> perform() async {
+    Future<void> perform({required bool isWarmUp}) async {
       var completionOffset = prefixEnd;
 
       if (insertStringGenerator != null) {
@@ -234,7 +230,7 @@
         );
       }
 
-      await test.complete(filePath, completionOffset);
+      await test.complete(filePath, completionOffset, isWarmUp: isWarmUp);
 
       if (insertStringGenerator != null) {
         await test.updateFile(filePath, fileContent);
@@ -246,13 +242,13 @@
     // The sustained performance is much more important.
     const kWarmUpCount = 5;
     for (var i = 0; i < kWarmUpCount; i++) {
-      await perform();
+      await perform(isWarmUp: true);
     }
 
     const kRepeatCount = 5;
     final timer = Stopwatch()..start();
     for (var i = 0; i < kRepeatCount; i++) {
-      await perform();
+      await perform(isWarmUp: false);
     }
 
     await test.closeFile(filePath);
diff --git a/pkg/analysis_server/benchmark/perf/memory_tests.dart b/pkg/analysis_server/benchmark/perf/memory_tests.dart
index 307b009..7836814 100644
--- a/pkg/analysis_server/benchmark/perf/memory_tests.dart
+++ b/pkg/analysis_server/benchmark/perf/memory_tests.dart
@@ -21,7 +21,7 @@
 abstract class AbstractBenchmarkTest {
   Future<void> get analysisFinished;
   Future<void> closeFile(String filePath);
-  Future<void> complete(String filePath, int offset);
+  Future<void> complete(String filePath, int offset, {required bool isWarmUp});
   void debugStdio();
   Future<int> getMemoryUsage();
   Future<void> openFile(String filePath, String contents);
@@ -44,22 +44,13 @@
       _test.sendAnalysisUpdateContent({filePath: RemoveContentOverlay()});
 
   @override
-  Future<void> complete(String filePath, int offset) async {
-    // Create a new non-broadcast stream and subscribe to
-    // test.onCompletionResults before sending a request.
-    // Otherwise we could skip results which where posted to
-    // test.onCompletionResults after request is sent but
-    // before subscribing to test.onCompletionResults.
-    final completionResults = StreamController<CompletionResultsParams>();
-    completionResults.sink.addStream(_test.onCompletionResults);
-
-    var result = await _test.sendCompletionGetSuggestions(filePath, offset);
-
-    var future = completionResults.stream
-        .where((CompletionResultsParams params) =>
-            params.id == result.id && params.isLast)
-        .first;
-    await future;
+  Future<void> complete(
+    String filePath,
+    int offset, {
+    required bool isWarmUp,
+  }) async {
+    await _test.sendCompletionGetSuggestions2(filePath, offset, 100,
+        timeout: isWarmUp ? 60 * 1000 : 0);
   }
 
   @override
@@ -80,7 +71,6 @@
     _test.dartSdkPath = dartSdkPath;
     await _test.setUp();
     await _test.subscribeToStatusNotifications();
-    await _test.subscribeToAvailableSuggestions();
     await _test.sendAnalysisSetAnalysisRoots(roots, []);
   }
 
@@ -129,16 +119,6 @@
   /// After every test, the server is stopped.
   Future shutdown() async => await shutdownIfNeeded();
 
-  /// Enable using available suggestions during completion.
-  Future<void> subscribeToAvailableSuggestions() async {
-    await server.send(
-      'completion.setSubscriptions',
-      CompletionSetSubscriptionsParams(
-        [CompletionService.AVAILABLE_SUGGESTION_SETS],
-      ).toJson(),
-    );
-  }
-
   /// Enable [ServerService.STATUS] notifications so that [analysisFinished]
   /// can be used.
   Future subscribeToStatusNotifications() async {
@@ -168,7 +148,7 @@
   }
 
   @override
-  Future<void> complete(String filePath, int offset) {
+  Future<void> complete(String filePath, int offset, {required bool isWarmUp}) {
     final contents = _fileContents[filePath]!;
     final position = _test.positionFromOffset(offset, contents);
     return _test.getCompletion(Uri.file(filePath), position);