Skip to content

Commit 863bc97

Browse files
jensjohaCommit Queue
authored andcommitted
[analyzer] Speedup receiving of data in benchmark
Change-Id: I3e37a1d8b17393ce3c41e33b1b90049c754cc595 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/436921 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Jens Johansen <[email protected]>
1 parent b374d42 commit 863bc97

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

pkg/analysis_server/tool/benchmark_tools/language_server_benchmark.dart

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'dart:async';
66
import 'dart:convert';
77
import 'dart:io';
8+
import 'dart:typed_data';
89

910
import 'io_utils.dart';
1011
import 'legacy_messages.dart';
@@ -19,7 +20,7 @@ abstract class DartLanguageServerBenchmark {
1920
bool _launched = false;
2021
bool _exited = false;
2122
Completer<bool> _analyzingCompleter = Completer();
22-
final _buffer = <int>[];
23+
final _buffer = _Uint8ListHelper();
2324
int? _headerContentLength;
2425
bool _printedVmServiceStuff = false;
2526
final String executableToUse;
@@ -347,11 +348,11 @@ abstract class DartLanguageServerBenchmark {
347348
_buffer.length % 1000 == 0) {
348349
print(
349350
'DEBUG MESSAGE: Stdout buffer with length ${_buffer.length} so far: '
350-
'${utf8.decode(_buffer)}',
351+
'${utf8.decode(_buffer.view())}',
351352
);
352353
}
353354
if (_lsp == true && _headerContentLength == null && _endsWithCrLfCrLf()) {
354-
String headerRaw = utf8.decode(_buffer);
355+
String headerRaw = utf8.decode(_buffer.view());
355356
_buffer.clear();
356357
// Use a regex that makes the '\r' optional to handle "The Dart VM service
357358
// is listening on [..." message - at least on linux - being \n terminated
@@ -377,7 +378,7 @@ abstract class DartLanguageServerBenchmark {
377378
_headerContentLength != null &&
378379
_buffer.length == _headerContentLength!) ||
379380
(_lsp == false && _endsWithLf())) {
380-
String messageString = utf8.decode(_buffer);
381+
String messageString = utf8.decode(_buffer.view());
381382
_buffer.clear();
382383
_headerContentLength = null;
383384

@@ -515,6 +516,34 @@ class OutstandingRequest {
515516
}
516517
}
517518

519+
class _Uint8ListHelper {
520+
Uint8List data;
521+
int length = 0;
522+
_Uint8ListHelper() : data = Uint8List(1024);
523+
524+
int operator [](int index) {
525+
if (index < 0 || index >= length) throw 'Out of bounds: $index';
526+
return data[index];
527+
}
528+
529+
void add(int i) {
530+
if (length == data.length) {
531+
var newData = Uint8List(length * 2);
532+
newData.setRange(0, length, data);
533+
data = newData;
534+
}
535+
data[length++] = i;
536+
}
537+
538+
void clear() {
539+
length = 0;
540+
}
541+
542+
Uint8List view() {
543+
return Uint8List.sublistView(data, 0, length);
544+
}
545+
}
546+
518547
extension on List<MemoryInfo> {
519548
void addInfoMaybe(String description, int? value) {
520549
if (value == null) return;

0 commit comments

Comments
 (0)