Skip to content

Commit 23f6f6d

Browse files
committed
isolate benchmark
1 parent ee61e4f commit 23f6f6d

File tree

2 files changed

+64
-4
lines changed

2 files changed

+64
-4
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 'dart:math';
6+
7+
import 'package:_pub_shared/search/search_form.dart';
8+
import 'package:pub_dev/search/search_service.dart';
9+
import 'package:pub_dev/service/entrypoint/_isolate.dart';
10+
import 'package:pub_dev/service/entrypoint/search_index.dart';
11+
12+
// NOTE: please add more queries to this list, especially if there is a performance bottleneck.
13+
final queries = [
14+
'sdk:dart',
15+
'sdk:flutter platform:android',
16+
'is:flutter-favorite',
17+
'chart',
18+
'json',
19+
'camera',
20+
'android camera',
21+
'sql database',
22+
];
23+
24+
Future<void> main(List<String> args) async {
25+
print('Loading...');
26+
final primaryRunner = await startSearchIsolate(snapshot: args.first);
27+
final reducedRunner = await startSearchIsolate(
28+
snapshot: args.first,
29+
removeTextContent: true,
30+
);
31+
print('Loaded.');
32+
33+
for (var i = 0; i < 5; i++) {
34+
await _benchmark(primaryRunner, primaryRunner);
35+
await _benchmark(primaryRunner, reducedRunner);
36+
print('--');
37+
}
38+
39+
await primaryRunner.close();
40+
await reducedRunner.close();
41+
}
42+
43+
Future<void> _benchmark(IsolateRunner primary, IsolateRunner reduced) async {
44+
final index = IsolateSearchIndex(primary, reduced);
45+
final sw = Stopwatch()..start();
46+
for (var i = 0; i < 10; i++) {
47+
final random = Random(i);
48+
final items = queries
49+
.expand((q) => List.generate(10, (_) => q))
50+
.map((q) => ServiceSearchQuery.parse(
51+
query: q,
52+
tagsPredicate: TagsPredicate.regularSearch(),
53+
))
54+
.toList();
55+
items.shuffle(random);
56+
await Future.wait(items.map((q) async => index.search(q)));
57+
}
58+
sw.stop();
59+
print(sw.elapsedMilliseconds);
60+
}

app/test/service/entrypoint/search_index_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ void main() {
5353
reducedPath,
5454
);
5555

56-
reducedRunner = await startSearchIsolate(snapshot: reducedPath);
57-
58-
await primaryRunner.start(1);
59-
await reducedRunner.start(1);
56+
reducedRunner = await startSearchIsolate(
57+
snapshot: reducedPath,
58+
removeTextContent: true,
59+
);
6060

6161
// index calling the sendport
6262
final searchIndex = IsolateSearchIndex(primaryRunner, reducedRunner);

0 commit comments

Comments
 (0)