From 78617979b20c4065c15eb40354724819702e2f3e Mon Sep 17 00:00:00 2001 From: William Hesse Date: Mon, 22 Jun 2020 23:45:55 +0000 Subject: [PATCH] Migrate Isolate benchmarks to null safety Change-Id: I420a60c58d9f727cf8d9cca99c211331ce8e3b57 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151844 Reviewed-by: Martin Kustermann --- benchmarks/Isolate/dart/Isolate.dart | 47 ++++++++-------- benchmarks/Isolate/dart2/Isolate.dart | 30 +++++----- benchmarks/IsolateJson/dart/IsolateJson.dart | 54 +++++++++--------- benchmarks/IsolateJson/dart2/IsolateJson.dart | 30 +++++----- .../IsolateSpawn/dart/IsolateSpawn.dart | 56 +++++++++---------- .../IsolateSpawn/dart2/IsolateSpawn.dart | 40 ++++++------- .../dart/IsolateSpawnMemory.dart | 36 ++++++------ .../dart2/IsolateSpawnMemory.dart | 36 ++++++------ 8 files changed, 161 insertions(+), 168 deletions(-) diff --git a/benchmarks/Isolate/dart/Isolate.dart b/benchmarks/Isolate/dart/Isolate.dart index 465d56a0ac6..b703340ce3f 100644 --- a/benchmarks/Isolate/dart/Isolate.dart +++ b/benchmarks/Isolate/dart/Isolate.dart @@ -8,11 +8,10 @@ import 'dart:typed_data'; import 'package:benchmark_harness/benchmark_harness.dart' show PrintEmitter, ScoreEmitter; -import 'package:meta/meta.dart'; class SendReceiveBytes extends AsyncBenchmarkBase { SendReceiveBytes(String name, - {@required int this.size, @required bool this.useTransferable}) + {required this.size, required this.useTransferable}) : super(name); @override @@ -33,7 +32,7 @@ class SendReceiveBytes extends AsyncBenchmarkBase { final bool useTransferable; final int size; - SendReceiveHelper helper; + late SendReceiveHelper helper; } // Identical to BenchmarkBase from package:benchmark_harness but async. @@ -86,10 +85,10 @@ class StartMessage { // Measures how long sending and receiving of [size]-length Uint8List takes. class SendReceiveHelper { - SendReceiveHelper(this.size, {@required bool this.useTransferable}); + SendReceiveHelper(this.size, {required this.useTransferable}); Future setup() async { - data = new Uint8List(size); + data = Uint8List(size); port = ReceivePort(); inbox = StreamIterator(port); @@ -121,24 +120,24 @@ class SendReceiveHelper { } } - Uint8List data; - ReceivePort port; - StreamIterator inbox; - SendPort outbox; - Isolate worker; - Completer workerCompleted; - ReceivePort workerExitedPort; + late Uint8List data; + late ReceivePort port; + late StreamIterator inbox; + late SendPort outbox; + late Isolate worker; + late Completer workerCompleted; + late ReceivePort workerExitedPort; final int size; final bool useTransferable; } -packageList(Uint8List data, bool useTransferable) => +Object packageList(Uint8List data, bool useTransferable) => useTransferable ? TransferableTypedData.fromList([data]) : data; Future isolate(StartMessage startMessage) async { final port = ReceivePort(); final inbox = StreamIterator(port); - final data = Uint8List.view(new Uint8List(startMessage.size).buffer); + final data = Uint8List.view(Uint8List(startMessage.size).buffer); startMessage.sendPort.send(port.sendPort); while (true) { @@ -163,22 +162,22 @@ class SizeName { final String name; } -final List sizes = [ - SizeName(1 * 1024, "1KB"), - SizeName(10 * 1024, "10KB"), - SizeName(100 * 1024, "100KB"), - SizeName(1 * 1024 * 1024, "1MB"), - SizeName(10 * 1024 * 1024, "10MB"), - SizeName(100 * 1024 * 1024, "100MB") +const List sizes = [ + SizeName(1 * 1024, '1KB'), + SizeName(10 * 1024, '10KB'), + SizeName(100 * 1024, '100KB'), + SizeName(1 * 1024 * 1024, '1MB'), + SizeName(10 * 1024 * 1024, '10MB'), + SizeName(100 * 1024 * 1024, '100MB') ]; Future main() async { - for (SizeName sizeName in sizes) { - await SendReceiveBytes("Isolate.SendReceiveBytes${sizeName.name}", + for (final sizeName in sizes) { + await SendReceiveBytes('Isolate.SendReceiveBytes${sizeName.name}', size: sizeName.size, useTransferable: false) .report(); await SendReceiveBytes( - "Isolate.SendReceiveBytesTransferable${sizeName.name}", + 'Isolate.SendReceiveBytesTransferable${sizeName.name}', size: sizeName.size, useTransferable: true) .report(); diff --git a/benchmarks/Isolate/dart2/Isolate.dart b/benchmarks/Isolate/dart2/Isolate.dart index 465d56a0ac6..aba6224e73a 100644 --- a/benchmarks/Isolate/dart2/Isolate.dart +++ b/benchmarks/Isolate/dart2/Isolate.dart @@ -12,7 +12,7 @@ import 'package:meta/meta.dart'; class SendReceiveBytes extends AsyncBenchmarkBase { SendReceiveBytes(String name, - {@required int this.size, @required bool this.useTransferable}) + {@required this.size, @required this.useTransferable}) : super(name); @override @@ -86,10 +86,10 @@ class StartMessage { // Measures how long sending and receiving of [size]-length Uint8List takes. class SendReceiveHelper { - SendReceiveHelper(this.size, {@required bool this.useTransferable}); + SendReceiveHelper(this.size, {@required this.useTransferable}); Future setup() async { - data = new Uint8List(size); + data = Uint8List(size); port = ReceivePort(); inbox = StreamIterator(port); @@ -132,13 +132,13 @@ class SendReceiveHelper { final bool useTransferable; } -packageList(Uint8List data, bool useTransferable) => +Object packageList(Uint8List data, bool useTransferable) => useTransferable ? TransferableTypedData.fromList([data]) : data; Future isolate(StartMessage startMessage) async { final port = ReceivePort(); final inbox = StreamIterator(port); - final data = Uint8List.view(new Uint8List(startMessage.size).buffer); + final data = Uint8List.view(Uint8List(startMessage.size).buffer); startMessage.sendPort.send(port.sendPort); while (true) { @@ -163,22 +163,22 @@ class SizeName { final String name; } -final List sizes = [ - SizeName(1 * 1024, "1KB"), - SizeName(10 * 1024, "10KB"), - SizeName(100 * 1024, "100KB"), - SizeName(1 * 1024 * 1024, "1MB"), - SizeName(10 * 1024 * 1024, "10MB"), - SizeName(100 * 1024 * 1024, "100MB") +const List sizes = [ + SizeName(1 * 1024, '1KB'), + SizeName(10 * 1024, '10KB'), + SizeName(100 * 1024, '100KB'), + SizeName(1 * 1024 * 1024, '1MB'), + SizeName(10 * 1024 * 1024, '10MB'), + SizeName(100 * 1024 * 1024, '100MB') ]; Future main() async { - for (SizeName sizeName in sizes) { - await SendReceiveBytes("Isolate.SendReceiveBytes${sizeName.name}", + for (final sizeName in sizes) { + await SendReceiveBytes('Isolate.SendReceiveBytes${sizeName.name}', size: sizeName.size, useTransferable: false) .report(); await SendReceiveBytes( - "Isolate.SendReceiveBytesTransferable${sizeName.name}", + 'Isolate.SendReceiveBytesTransferable${sizeName.name}', size: sizeName.size, useTransferable: true) .report(); diff --git a/benchmarks/IsolateJson/dart/IsolateJson.dart b/benchmarks/IsolateJson/dart/IsolateJson.dart index 1fa491950bd..5b5a9ee7d80 100644 --- a/benchmarks/IsolateJson/dart/IsolateJson.dart +++ b/benchmarks/IsolateJson/dart/IsolateJson.dart @@ -9,15 +9,14 @@ import 'dart:isolate'; import 'dart:typed_data'; import 'package:benchmark_harness/benchmark_harness.dart' show BenchmarkBase; -import 'package:meta/meta.dart'; import 'runtime/tests/vm/dart/export_sendAndExit_helper.dart' show sendAndExit; class JsonDecodingBenchmark { JsonDecodingBenchmark(this.name, - {@required this.sample, - @required this.numTasks, - @required this.useSendAndExit}); + {required this.sample, + required this.numTasks, + required this.useSendAndExit}); Future report() async { final stopwatch = Stopwatch()..start(); @@ -30,7 +29,7 @@ class JsonDecodingBenchmark { await Future.wait(decodedFutures); } - print("$name(RunTime): ${stopwatch.elapsedMicroseconds} us."); + print('$name(RunTime): ${stopwatch.elapsedMicroseconds} us.'); } final String name; @@ -45,7 +44,7 @@ Uint8List createSampleJson(final size) { for (int i = 0; i < size; i++) { map['$i'] = list; } - return utf8.encode(json.encode(map)); + return utf8.encode(json.encode(map)) as Uint8List; } class JsonDecodeRequest { @@ -73,7 +72,7 @@ Future decodeJson(bool useSendAndExit, Uint8List encodedJson) async { workerExitedPort.close(); workerErroredPort.close(); await inbox.moveNext(); - final decodedJson = inbox.current; + final decodedJson = inbox.current as Map; port.close(); return decodedJson; } @@ -89,7 +88,7 @@ Future jsonDecodingIsolate(JsonDecodeRequest request) async { class SyncJsonDecodingBenchmark extends BenchmarkBase { SyncJsonDecodingBenchmark(String name, - {@required this.sample, @required this.iterations}) + {required this.sample, required this.iterations}) : super(name); @override @@ -116,43 +115,46 @@ class BenchmarkConfig { Future main() async { final jsonString = File('benchmarks/IsolateJson/dart/sample.json').readAsStringSync(); - final json250KB = utf8.encode(jsonString); // 294356 bytes + final json250KB = utf8.encode(jsonString) as Uint8List; // 294356 bytes final decoded = json.decode(utf8.decode(json250KB)); final decoded1MB = { - "1": decoded["1"], - "2": decoded["1"], - "3": decoded["1"], - "4": decoded["1"], + '1': decoded['1'], + '2': decoded['1'], + '3': decoded['1'], + '4': decoded['1'], }; - final json1MB = utf8.encode(json.encode(decoded1MB)); // 1177397 bytes - decoded["1"] = (decoded["1"] as List).sublist(0, 200); - final json100KB = utf8.encode(json.encode(decoded)); // 104685 bytes - decoded["1"] = (decoded["1"] as List).sublist(0, 100); - final json50KB = utf8.encode(json.encode(decoded)); // 51760 bytes + final json1MB = + utf8.encode(json.encode(decoded1MB)) as Uint8List; // 1177397 bytes + decoded['1'] = (decoded['1'] as List).sublist(0, 200); + final json100KB = + utf8.encode(json.encode(decoded)) as Uint8List; // 104685 bytes + decoded['1'] = (decoded['1'] as List).sublist(0, 100); + final json50KB = + utf8.encode(json.encode(decoded)) as Uint8List; // 51760 bytes final configs = [ - BenchmarkConfig("50KB", json50KB), - BenchmarkConfig("100KB", json100KB), - BenchmarkConfig("250KB", json250KB), - BenchmarkConfig("1MB", json1MB), + BenchmarkConfig('50KB', json50KB), + BenchmarkConfig('100KB', json100KB), + BenchmarkConfig('250KB', json250KB), + BenchmarkConfig('1MB', json1MB), ]; - for (BenchmarkConfig config in configs) { + for (final config in configs) { for (final iterations in [1, 4]) { await JsonDecodingBenchmark( - "IsolateJson.Decode${config.suffix}x$iterations", + 'IsolateJson.Decode${config.suffix}x$iterations', useSendAndExit: false, sample: config.sample, numTasks: iterations) .report(); await JsonDecodingBenchmark( - "IsolateJson.SendAndExit_Decode${config.suffix}x$iterations", + 'IsolateJson.SendAndExit_Decode${config.suffix}x$iterations', useSendAndExit: true, sample: config.sample, numTasks: iterations) .report(); SyncJsonDecodingBenchmark( - "IsolateJson.SyncDecode${config.suffix}x$iterations", + 'IsolateJson.SyncDecode${config.suffix}x$iterations', sample: config.sample, iterations: iterations) .report(); diff --git a/benchmarks/IsolateJson/dart2/IsolateJson.dart b/benchmarks/IsolateJson/dart2/IsolateJson.dart index 459c1334b30..4e64477c5da 100644 --- a/benchmarks/IsolateJson/dart2/IsolateJson.dart +++ b/benchmarks/IsolateJson/dart2/IsolateJson.dart @@ -30,7 +30,7 @@ class JsonDecodingBenchmark { await Future.wait(decodedFutures); } - print("$name(RunTime): ${stopwatch.elapsedMicroseconds} us."); + print('$name(RunTime): ${stopwatch.elapsedMicroseconds} us.'); } final String name; @@ -119,40 +119,40 @@ Future main() async { final json250KB = utf8.encode(jsonString); // 294356 bytes final decoded = json.decode(utf8.decode(json250KB)); final decoded1MB = { - "1": decoded["1"], - "2": decoded["1"], - "3": decoded["1"], - "4": decoded["1"], + '1': decoded['1'], + '2': decoded['1'], + '3': decoded['1'], + '4': decoded['1'], }; final json1MB = utf8.encode(json.encode(decoded1MB)); // 1177397 bytes - decoded["1"] = (decoded["1"] as List).sublist(0, 200); + decoded['1'] = (decoded['1'] as List).sublist(0, 200); final json100KB = utf8.encode(json.encode(decoded)); // 104685 bytes - decoded["1"] = (decoded["1"] as List).sublist(0, 100); + decoded['1'] = (decoded['1'] as List).sublist(0, 100); final json50KB = utf8.encode(json.encode(decoded)); // 51760 bytes final configs = [ - BenchmarkConfig("50KB", json50KB), - BenchmarkConfig("100KB", json100KB), - BenchmarkConfig("250KB", json250KB), - BenchmarkConfig("1MB", json1MB), + BenchmarkConfig('50KB', json50KB), + BenchmarkConfig('100KB', json100KB), + BenchmarkConfig('250KB', json250KB), + BenchmarkConfig('1MB', json1MB), ]; - for (BenchmarkConfig config in configs) { + for (final config in configs) { for (final iterations in [1, 4]) { await JsonDecodingBenchmark( - "IsolateJson.Decode${config.suffix}x$iterations", + 'IsolateJson.Decode${config.suffix}x$iterations', useSendAndExit: false, sample: config.sample, numTasks: iterations) .report(); await JsonDecodingBenchmark( - "IsolateJson.SendAndExit_Decode${config.suffix}x$iterations", + 'IsolateJson.SendAndExit_Decode${config.suffix}x$iterations', useSendAndExit: true, sample: config.sample, numTasks: iterations) .report(); SyncJsonDecodingBenchmark( - "IsolateJson.SyncDecode${config.suffix}x$iterations", + 'IsolateJson.SyncDecode${config.suffix}x$iterations', sample: config.sample, iterations: iterations) .report(); diff --git a/benchmarks/IsolateSpawn/dart/IsolateSpawn.dart b/benchmarks/IsolateSpawn/dart/IsolateSpawn.dart index 5742568f9ee..6212abe382a 100644 --- a/benchmarks/IsolateSpawn/dart/IsolateSpawn.dart +++ b/benchmarks/IsolateSpawn/dart/IsolateSpawn.dart @@ -6,8 +6,6 @@ import 'dart:async'; import 'dart:isolate'; import 'dart:math'; -import 'package:meta/meta.dart'; - import 'package:compiler/src/dart2js.dart' as dart2js_main; class SpawnLatency { @@ -16,17 +14,17 @@ class SpawnLatency { Future run() async { final completerResult = Completer(); final receivePort = ReceivePort()..listen(completerResult.complete); - final Completer isolateExitedCompleter = Completer(); + final isolateExitedCompleter = Completer(); final onExitReceivePort = ReceivePort() ..listen((_) { isolateExitedCompleter.complete(DateTime.now()); }); - final DateTime beforeSpawn = DateTime.now(); + final beforeSpawn = DateTime.now(); await Isolate.spawn( isolateCompiler, StartMessageLatency(receivePort.sendPort, beforeSpawn), onExit: onExitReceivePort.sendPort, onError: onExitReceivePort.sendPort); - final DateTime afterSpawn = DateTime.now(); + final afterSpawn = DateTime.now(); final ResultMessageLatency result = await completerResult.future; receivePort.close(); @@ -42,13 +40,13 @@ class SpawnLatency { Future measureFor(int minimumMillis) async { final minimumMicros = minimumMillis * 1000; final watch = Stopwatch()..start(); - final Metric toAfterIsolateSpawnUs = LatencyMetric("${name}ToAfterSpawn"); - final Metric toStartRunningCodeUs = LatencyMetric("${name}ToStartRunning"); + final Metric toAfterIsolateSpawnUs = LatencyMetric('${name}ToAfterSpawn'); + final Metric toStartRunningCodeUs = LatencyMetric('${name}ToStartRunning'); final Metric toFinishRunningCodeUs = - LatencyMetric("${name}ToFinishRunning"); - final Metric toExitUs = LatencyMetric("${name}ToExit"); + LatencyMetric('${name}ToFinishRunning'); + final Metric toExitUs = LatencyMetric('${name}ToExit'); while (watch.elapsedMicroseconds < minimumMicros) { - final ResultMessageLatency result = await run(); + final result = await run(); toAfterIsolateSpawnUs.add(result.timeToIsolateSpawnUs); toStartRunningCodeUs.add(result.timeToStartRunningCodeUs); toFinishRunningCodeUs.add(result.timeToFinishRunningCodeUs); @@ -64,16 +62,16 @@ class SpawnLatency { } Future report() async { - final AggregatedResultMessageLatency result = await measure(); + final result = await measure(); print(result); } final String name; - RawReceivePort receivePort; + late RawReceivePort receivePort; } class Metric { - Metric({@required this.prefix, @required this.suffix}); + Metric({required this.prefix, required this.suffix}); void add(int value) { if (value > max) { @@ -87,9 +85,10 @@ class Metric { double _average() => sum / count; double _rms() => sqrt(sumOfSquares / count); - toString() => "$prefix): ${_average()}$suffix\n" - "${prefix}Max): $max$suffix\n" - "${prefix}RMS): ${_rms()}$suffix"; + @override + String toString() => '$prefix): ${_average()}$suffix\n' + '${prefix}Max): $max$suffix\n' + '${prefix}RMS): ${_rms()}$suffix'; final String prefix; final String suffix; @@ -100,7 +99,7 @@ class Metric { } class LatencyMetric extends Metric { - LatencyMetric(String name) : super(prefix: "$name(Latency", suffix: " us."); + LatencyMetric(String name) : super(prefix: '$name(Latency', suffix: ' us.'); } class StartMessageLatency { @@ -112,16 +111,14 @@ class StartMessageLatency { class ResultMessageLatency { ResultMessageLatency( - {this.timeToStartRunningCodeUs, - this.timeToFinishRunningCodeUs, - this.deltaHeap}); + {required this.timeToStartRunningCodeUs, + required this.timeToFinishRunningCodeUs}); final int timeToStartRunningCodeUs; final int timeToFinishRunningCodeUs; - final int deltaHeap; - int timeToIsolateSpawnUs; - int timeToExitUs; + late int timeToIsolateSpawnUs; + late int timeToExitUs; } class AggregatedResultMessageLatency { @@ -132,10 +129,11 @@ class AggregatedResultMessageLatency { this.toExitUs, ); - String toString() => """$toAfterIsolateSpawnUs + @override + String toString() => '''$toAfterIsolateSpawnUs $toStartRunningCodeUs $toFinishRunningCodeUs -$toExitUs"""; +$toExitUs'''; final Metric toAfterIsolateSpawnUs; final Metric toStartRunningCodeUs; @@ -144,15 +142,15 @@ $toExitUs"""; } Future isolateCompiler(StartMessageLatency start) async { - final DateTime timeRunningCodeUs = DateTime.now(); + final timeRunningCodeUs = DateTime.now(); await runZoned( () => dart2js_main.internalMain([ - "benchmarks/IsolateSpawn/dart/helloworld.dart", + 'benchmarks/IsolateSpawn/dart/helloworld.dart', '--libraries-spec=sdk/lib/libraries.json' ]), zoneSpecification: ZoneSpecification( print: (Zone self, ZoneDelegate parent, Zone zone, String line) {})); - final DateTime timeFinishRunningCodeUs = DateTime.now(); + final timeFinishRunningCodeUs = DateTime.now(); start.sendPort.send(ResultMessageLatency( timeToStartRunningCodeUs: timeRunningCodeUs.difference(start.spawned).inMicroseconds, @@ -161,5 +159,5 @@ Future isolateCompiler(StartMessageLatency start) async { } Future main() async { - await SpawnLatency("IsolateSpawn.Dart2JS").report(); + await SpawnLatency('IsolateSpawn.Dart2JS').report(); } diff --git a/benchmarks/IsolateSpawn/dart2/IsolateSpawn.dart b/benchmarks/IsolateSpawn/dart2/IsolateSpawn.dart index e8ec25cf5e6..a7544415f53 100644 --- a/benchmarks/IsolateSpawn/dart2/IsolateSpawn.dart +++ b/benchmarks/IsolateSpawn/dart2/IsolateSpawn.dart @@ -16,17 +16,17 @@ class SpawnLatency { Future run() async { final completerResult = Completer(); final receivePort = ReceivePort()..listen(completerResult.complete); - final Completer isolateExitedCompleter = Completer(); + final isolateExitedCompleter = Completer(); final onExitReceivePort = ReceivePort() ..listen((_) { isolateExitedCompleter.complete(DateTime.now()); }); - final DateTime beforeSpawn = DateTime.now(); + final beforeSpawn = DateTime.now(); await Isolate.spawn( isolateCompiler, StartMessageLatency(receivePort.sendPort, beforeSpawn), onExit: onExitReceivePort.sendPort, onError: onExitReceivePort.sendPort); - final DateTime afterSpawn = DateTime.now(); + final afterSpawn = DateTime.now(); final ResultMessageLatency result = await completerResult.future; receivePort.close(); @@ -42,13 +42,13 @@ class SpawnLatency { Future measureFor(int minimumMillis) async { final minimumMicros = minimumMillis * 1000; final watch = Stopwatch()..start(); - final Metric toAfterIsolateSpawnUs = LatencyMetric("${name}ToAfterSpawn"); - final Metric toStartRunningCodeUs = LatencyMetric("${name}ToStartRunning"); + final Metric toAfterIsolateSpawnUs = LatencyMetric('${name}ToAfterSpawn'); + final Metric toStartRunningCodeUs = LatencyMetric('${name}ToStartRunning'); final Metric toFinishRunningCodeUs = - LatencyMetric("${name}ToFinishRunning"); - final Metric toExitUs = LatencyMetric("${name}ToExit"); + LatencyMetric('${name}ToFinishRunning'); + final Metric toExitUs = LatencyMetric('${name}ToExit'); while (watch.elapsedMicroseconds < minimumMicros) { - final ResultMessageLatency result = await run(); + final result = await run(); toAfterIsolateSpawnUs.add(result.timeToIsolateSpawnUs); toStartRunningCodeUs.add(result.timeToStartRunningCodeUs); toFinishRunningCodeUs.add(result.timeToFinishRunningCodeUs); @@ -64,7 +64,7 @@ class SpawnLatency { } Future report() async { - final AggregatedResultMessageLatency result = await measure(); + final result = await measure(); print(result); } @@ -87,9 +87,10 @@ class Metric { double _average() => sum / count; double _rms() => sqrt(sumOfSquares / count); - toString() => "$prefix): ${_average()}$suffix\n" - "${prefix}Max): $max$suffix\n" - "${prefix}RMS): ${_rms()}$suffix"; + @override + String toString() => '$prefix): ${_average()}$suffix\n' + '${prefix}Max): $max$suffix\n' + '${prefix}RMS): ${_rms()}$suffix'; final String prefix; final String suffix; @@ -100,7 +101,7 @@ class Metric { } class LatencyMetric extends Metric { - LatencyMetric(String name) : super(prefix: "$name(Latency", suffix: " us."); + LatencyMetric(String name) : super(prefix: '$name(Latency', suffix: ' us.'); } class StartMessageLatency { @@ -132,10 +133,11 @@ class AggregatedResultMessageLatency { this.toExitUs, ); - String toString() => """$toAfterIsolateSpawnUs + @override + String toString() => '''$toAfterIsolateSpawnUs $toStartRunningCodeUs $toFinishRunningCodeUs -$toExitUs"""; +$toExitUs'''; final Metric toAfterIsolateSpawnUs; final Metric toStartRunningCodeUs; @@ -144,15 +146,15 @@ $toExitUs"""; } Future isolateCompiler(StartMessageLatency start) async { - final DateTime timeRunningCodeUs = DateTime.now(); + final timeRunningCodeUs = DateTime.now(); await runZoned( () => dart2js_main.internalMain([ - "benchmarks/IsolateSpawn/dart2/helloworld.dart", + 'benchmarks/IsolateSpawn/dart/helloworld.dart', '--libraries-spec=sdk/lib/libraries.json' ]), zoneSpecification: ZoneSpecification( print: (Zone self, ZoneDelegate parent, Zone zone, String line) {})); - final DateTime timeFinishRunningCodeUs = DateTime.now(); + final timeFinishRunningCodeUs = DateTime.now(); start.sendPort.send(ResultMessageLatency( timeToStartRunningCodeUs: timeRunningCodeUs.difference(start.spawned).inMicroseconds, @@ -161,5 +163,5 @@ Future isolateCompiler(StartMessageLatency start) async { } Future main() async { - await SpawnLatency("IsolateSpawn.Dart2JS").report(); + await SpawnLatency('IsolateSpawn.Dart2JS').report(); } diff --git a/benchmarks/IsolateSpawnMemory/dart/IsolateSpawnMemory.dart b/benchmarks/IsolateSpawnMemory/dart/IsolateSpawnMemory.dart index 322f1af6e86..1f7b009fdca 100644 --- a/benchmarks/IsolateSpawnMemory/dart/IsolateSpawnMemory.dart +++ b/benchmarks/IsolateSpawnMemory/dart/IsolateSpawnMemory.dart @@ -96,11 +96,11 @@ class SpawnMemory { final doneDiffHeap = math.max(0, doneHeap - beforeHeap) ~/ numberOfBenchmarks; - print("${name}RssOnStart(MemoryUse): $readyDiffRss"); - print("${name}RssOnEnd(MemoryUse): $doneDiffRss"); - print("${name}HeapOnStart(MemoryUse): $readyDiffHeap"); - print("${name}HeapOnEnd(MemoryUse): $doneDiffHeap"); - print("${name}PeakProcessRss(MemoryUse): $maxProcessRss"); + print('${name}RssOnStart(MemoryUse): $readyDiffRss'); + print('${name}RssOnEnd(MemoryUse): $doneDiffRss'); + print('${name}HeapOnStart(MemoryUse): $readyDiffHeap'); + print('${name}HeapOnEnd(MemoryUse): $doneDiffHeap'); + print('${name}PeakProcessRss(MemoryUse): $maxProcessRss'); } final String name; @@ -117,7 +117,7 @@ Future isolateCompiler(StartMessage startMessage) async { await runZoned( () => dart2js_main.internalMain([ - "benchmarks/IsolateSpawnMemory/dart/helloworld.dart", + 'benchmarks/IsolateSpawnMemory/dart/helloworld.dart', '--libraries-spec=sdk/lib/libraries.json' ]), zoneSpecification: ZoneSpecification( @@ -133,13 +133,11 @@ Future isolateCompiler(StartMessage startMessage) async { } Future currentHeapUsage(String wsUri) async { - final vm_service.VmService vmService = - await vm_service_io.vmServiceConnectUri(wsUri); + final vmService = await vm_service_io.vmServiceConnectUri(wsUri); final groupIds = await getGroupIds(vmService); int sum = 0; for (final groupId in groupIds) { - final vm_service.MemoryUsage usage = - await vmService.getIsolateGroupMemoryUsage(groupId); + final usage = await vmService.getIsolateGroupMemoryUsage(groupId); sum += usage.heapUsage + usage.externalUsage; } vmService.dispose(); @@ -150,11 +148,10 @@ Future main() async { // Only if we successfully reach the end will we set 0 exit code. exitCode = 255; - final ServiceProtocolInfo info = await Service.controlWebServer(enable: true); - final Uri observatoryUri = info.serverUri; - final String wsUri = - 'ws://${observatoryUri.authority}${observatoryUri.path}ws'; - await SpawnMemory("IsolateSpawnMemory.Dart2JSDelta", wsUri).report(); + final info = await Service.controlWebServer(enable: true); + final observatoryUri = info.serverUri!; + final wsUri = 'ws://${observatoryUri.authority}${observatoryUri.path}ws'; + await SpawnMemory('IsolateSpawnMemory.Dart2JSDelta', wsUri).report(); // Only if we successfully reach the end will we set 0 exit code. exitCode = 0; @@ -174,10 +171,9 @@ Future main() async { Future> getGroupIds(vm_service.VmService vmService) async { final groupIds = {}; final vm = await vmService.getVM(); - for (vm_service.IsolateGroupRef groupRef in vm.isolateGroups) { - final vm_service.IsolateGroup group = - await vmService.getIsolateGroup(groupRef.id); - for (vm_service.IsolateRef isolateRef in group.isolates) { + for (final groupRef in vm.isolateGroups) { + final group = await vmService.getIsolateGroup(groupRef.id); + for (final isolateRef in group.isolates) { final isolateOrSentinel = await vmService.getIsolate(isolateRef.id); if (isolateOrSentinel is vm_service.Isolate) { groupIds.add(groupRef.id); @@ -185,7 +181,7 @@ Future> getGroupIds(vm_service.VmService vmService) async { } } if (groupIds.isEmpty) { - throw "Could not find main isolate"; + throw 'Could not find main isolate'; } return groupIds.toList(); } diff --git a/benchmarks/IsolateSpawnMemory/dart2/IsolateSpawnMemory.dart b/benchmarks/IsolateSpawnMemory/dart2/IsolateSpawnMemory.dart index 609a8c23636..5a13d965ebe 100644 --- a/benchmarks/IsolateSpawnMemory/dart2/IsolateSpawnMemory.dart +++ b/benchmarks/IsolateSpawnMemory/dart2/IsolateSpawnMemory.dart @@ -96,11 +96,11 @@ class SpawnMemory { final doneDiffHeap = math.max(0, doneHeap - beforeHeap) ~/ numberOfBenchmarks; - print("${name}RssOnStart(MemoryUse): $readyDiffRss"); - print("${name}RssOnEnd(MemoryUse): $doneDiffRss"); - print("${name}HeapOnStart(MemoryUse): $readyDiffHeap"); - print("${name}HeapOnEnd(MemoryUse): $doneDiffHeap"); - print("${name}PeakProcessRss(MemoryUse): $maxProcessRss"); + print('${name}RssOnStart(MemoryUse): $readyDiffRss'); + print('${name}RssOnEnd(MemoryUse): $doneDiffRss'); + print('${name}HeapOnStart(MemoryUse): $readyDiffHeap'); + print('${name}HeapOnEnd(MemoryUse): $doneDiffHeap'); + print('${name}PeakProcessRss(MemoryUse): $maxProcessRss'); } final String name; @@ -117,7 +117,7 @@ Future isolateCompiler(StartMessage startMessage) async { await runZoned( () => dart2js_main.internalMain([ - "benchmarks/IsolateSpawnMemory/dart2/helloworld.dart", + 'benchmarks/IsolateSpawnMemory/dart/helloworld.dart', '--libraries-spec=sdk/lib/libraries.json' ]), zoneSpecification: ZoneSpecification( @@ -133,13 +133,11 @@ Future isolateCompiler(StartMessage startMessage) async { } Future currentHeapUsage(String wsUri) async { - final vm_service.VmService vmService = - await vm_service_io.vmServiceConnectUri(wsUri); + final vmService = await vm_service_io.vmServiceConnectUri(wsUri); final groupIds = await getGroupIds(vmService); int sum = 0; for (final groupId in groupIds) { - final vm_service.MemoryUsage usage = - await vmService.getIsolateGroupMemoryUsage(groupId); + final usage = await vmService.getIsolateGroupMemoryUsage(groupId); sum += usage.heapUsage + usage.externalUsage; } vmService.dispose(); @@ -150,11 +148,10 @@ Future main() async { // Only if we successfully reach the end will we set 0 exit code. exitCode = 255; - final ServiceProtocolInfo info = await Service.controlWebServer(enable: true); - final Uri observatoryUri = info.serverUri; - final String wsUri = - 'ws://${observatoryUri.authority}${observatoryUri.path}ws'; - await SpawnMemory("IsolateSpawnMemory.Dart2JSDelta", wsUri).report(); + final info = await Service.controlWebServer(enable: true); + final observatoryUri = info.serverUri; + final wsUri = 'ws://${observatoryUri.authority}${observatoryUri.path}ws'; + await SpawnMemory('IsolateSpawnMemory.Dart2JSDelta', wsUri).report(); // Only if we successfully reach the end will we set 0 exit code. exitCode = 0; @@ -174,10 +171,9 @@ Future main() async { Future> getGroupIds(vm_service.VmService vmService) async { final groupIds = {}; final vm = await vmService.getVM(); - for (vm_service.IsolateGroupRef groupRef in vm.isolateGroups) { - final vm_service.IsolateGroup group = - await vmService.getIsolateGroup(groupRef.id); - for (vm_service.IsolateRef isolateRef in group.isolates) { + for (final groupRef in vm.isolateGroups) { + final group = await vmService.getIsolateGroup(groupRef.id); + for (final isolateRef in group.isolates) { final isolateOrSentinel = await vmService.getIsolate(isolateRef.id); if (isolateOrSentinel is vm_service.Isolate) { groupIds.add(groupRef.id); @@ -185,7 +181,7 @@ Future> getGroupIds(vm_service.VmService vmService) async { } } if (groupIds.isEmpty) { - throw "Could not find main isolate"; + throw 'Could not find main isolate'; } return groupIds.toList(); }