Skip to content

Commit 0814785

Browse files
jensjohaCommit Queue
authored andcommitted
[analysis server] Keep more of the recent requests
* Bump kept requests from 50 to 250 * Make the request storage (`RecentBuffer`) add in constant time instead of linear time (modulo the `n` in `O(n)` being the constant 50 or 250 making the before theoretically constant too, but anyway). Change-Id: Ib00bd038b06f167fd7298a87402a89a23fd53880 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/457025 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Jens Johansen <[email protected]>
1 parent eaa7368 commit 0814785

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

pkg/analysis_server/lib/src/analysis_server.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,7 @@ enum MessageType {
13051305

13061306
class ServerRecentPerformance {
13071307
/// The maximum number of performance measurements to keep.
1308-
static const int performanceListMaxLength = 50;
1308+
static const int performanceListMaxLength = 250;
13091309

13101310
/// The maximum number of slow performance measurements to keep.
13111311
static const int slowRequestsListMaxLength = 1000;

pkg/analysis_server/lib/src/collections.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'dart:collection';
6+
57
/// Returns the given [list] if it is not empty, or `null` otherwise.
68
List<E>? nullIfEmpty<E>(List<E>? list) {
79
if (list == null || list.isEmpty) {
@@ -17,17 +19,16 @@ List<E>? nullIfEmpty<E>(List<E>? list) {
1719
class RecentBuffer<T> {
1820
final int capacity;
1921

20-
final List<T> _buffer = [];
22+
final Queue<T> _buffer;
2123

22-
RecentBuffer(this.capacity);
24+
RecentBuffer(this.capacity) : _buffer = Queue();
2325

24-
Iterable<T> get items => _buffer.reversed;
26+
Iterable<T> get items => _buffer;
2527

2628
void add(T item) {
27-
_buffer.add(item);
28-
29-
if (_buffer.length > capacity) {
30-
_buffer.removeAt(0);
29+
while (_buffer.length >= capacity) {
30+
_buffer.removeLast();
3131
}
32+
_buffer.addFirst(item);
3233
}
3334
}

0 commit comments

Comments
 (0)