Skip to content

Commit 455a105

Browse files
aamcommit-bot@chromium.org
authored andcommitted
[vm/benchmark] Introduce benchmarks that measures event loop latency for regexp processing.
This captures performance issues reported on flutter/flutter#88063 Change-Id: Ie216808a02231be7915c60268718f3e0a0dc3c99 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210282 Reviewed-by: Martin Kustermann <[email protected]> Commit-Queue: Alexander Aprelev <[email protected]>
1 parent 9eabbf1 commit 455a105

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) 2021, 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 'dart:isolate';
6+
7+
import 'regexp_benchmark.dart';
8+
import '../../EventLoopLatencyJson/dart/latency.dart';
9+
10+
main() async {
11+
final exitPort = ReceivePort();
12+
final exitFuture = exitPort.first;
13+
final isolate = await Isolate.spawn(run, null, onExit: exitPort.sendPort);
14+
15+
// Measure event loop latency.
16+
const tickDuration = const Duration(milliseconds: 1);
17+
const numberOfTicks = 8 * 1000; // min 8 seconds.
18+
final EventLoopLatencyStats stats =
19+
await measureEventLoopLatency(tickDuration, numberOfTicks);
20+
21+
// Kill isolate & wait until it's dead.
22+
isolate.kill(priority: Isolate.immediate);
23+
await exitFuture;
24+
25+
// Report event loop latency statistics.
26+
stats.report('EventLoopLatencyRegexp');
27+
}
28+
29+
void run(dynamic msg) {
30+
while (true) {
31+
RegexpBenchmark().run();
32+
}
33+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) 2021, 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 'dart:math';
6+
import 'dart:convert';
7+
8+
class RegexpBenchmark {
9+
void run() {
10+
final re = RegExp(r'(x+)*y');
11+
final s = 'x' * 26 + '';
12+
re.allMatches(s).iterator.moveNext();
13+
}
14+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) 2020, 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+
// @dart=2.9
6+
7+
import 'dart:isolate';
8+
9+
import 'json_benchmark.dart';
10+
import '../../EventLoopLatencyJson/dart2/latency.dart';
11+
12+
main() async {
13+
final exitPort = ReceivePort();
14+
final exitFuture = exitPort.first;
15+
final isolate = await Isolate.spawn(run, null, onExit: exitPort.sendPort);
16+
17+
// Measure event loop latency.
18+
const tickDuration = const Duration(milliseconds: 1);
19+
const numberOfTicks = 8 * 1000; // min 8 seconds.
20+
final EventLoopLatencyStats stats =
21+
await measureEventLoopLatency(tickDuration, numberOfTicks);
22+
23+
// Kill isolate & wait until it's dead.
24+
isolate.kill(priority: Isolate.immediate);
25+
await exitFuture;
26+
27+
// Report event loop latency statistics.
28+
stats.report('EventLoopLatencyRegexp');
29+
}
30+
31+
void run(dynamic msg) {
32+
while (true) {
33+
RegexpBenchmark().run();
34+
}
35+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) 2021, 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+
// @dart=2.9
6+
7+
import 'dart:math';
8+
import 'dart:convert';
9+
10+
class RegexpBenchmark {
11+
void run() {
12+
final re = RegExp(r'(x+)*y');
13+
final s = 'x' * 26 + '';
14+
re.allMatches(s).iterator.moveNext();
15+
}
16+
}

0 commit comments

Comments
 (0)