mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 17:40:04 +00:00
af1b5b8044
We want dart2wasm be comparable to dart2js / dart2aot, the ladder two are much more conservative with inlining compared to current dart2wasm. The -O3 is described in the binaryen sources as agressive for performance and therefore willing to compromise code size. The -Os is more nuanced: It will perform many optimizations that are done in -O3 (and e.g. not in -O2) but it will make inlining less agressive. This reduces flute compile-time by 10% and code size by 10% This benchmark results are mixed (some things get faster, some things slower). Naturally there'll be specialized micro benchmarks that get hit hard by this. Where performance matters we should rather make dart2wasm use better inlining heuristics and annotate code with `@pragma('wasm:prefer-inline')` Change-Id: Idf7e75e4e385629c9cec66359efe0afe50db3e72 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352523 Reviewed-by: Slava Egorov <vegorov@google.com> Commit-Queue: Martin Kustermann <kustermann@google.com>
107 lines
2.7 KiB
Dart
107 lines
2.7 KiB
Dart
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
//
|
|
// Generates both the dart and dart2 version of this benchmark.
|
|
|
|
import 'dart:io';
|
|
import 'dart:math';
|
|
|
|
import 'package:path/path.dart' as path;
|
|
|
|
const String benchmarkName = 'InstantiateTypeArgs';
|
|
|
|
const List<int> instantiateCounts = [1, 5, 10, 100, 1000];
|
|
|
|
void generateBenchmarkClassesAndUtilities(IOSink output, {required bool nnbd}) {
|
|
output.writeln('''
|
|
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
//
|
|
// This benchmark suite measures the overhead of instantiating type arguments,
|
|
// with a particular aim of measuring the overhead of the caching mechanism.
|
|
''');
|
|
|
|
if (!nnbd) {
|
|
output.writeln('''
|
|
// @dart=2.9"
|
|
''');
|
|
}
|
|
|
|
output.write('''
|
|
import 'package:benchmark_harness/benchmark_harness.dart';
|
|
|
|
void main() {
|
|
''');
|
|
for (final count in instantiateCounts) {
|
|
output.write('''
|
|
const Instantiate$count().report();
|
|
''');
|
|
}
|
|
output.writeln('''
|
|
}
|
|
''');
|
|
|
|
for (final count in instantiateCounts) {
|
|
output.write('''
|
|
class Instantiate$count extends BenchmarkBase {
|
|
const Instantiate$count() : super('$benchmarkName.Instantiate$count');
|
|
|
|
// Normalize the cost across the benchmarks by number of instantiations.
|
|
@override
|
|
void report() => emitter.emit(name, measure() / $count);
|
|
|
|
@override
|
|
void run() {
|
|
''');
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
output.write('''
|
|
D.instantiate<C$i>();
|
|
''');
|
|
}
|
|
|
|
output.writeln('''
|
|
}
|
|
}
|
|
''');
|
|
}
|
|
|
|
output.write('''
|
|
@pragma('vm:never-inline')
|
|
@pragma('wasm:never-inline')
|
|
@pragma('dart2js:never-inline')
|
|
void blackhole<T>() => null;
|
|
|
|
class D<T> {
|
|
@pragma('vm:never-inline')
|
|
@pragma('wasm:never-inline')
|
|
@pragma('dart2js:never-inline')
|
|
static void instantiate<S>() => blackhole<D<S>>();
|
|
}
|
|
''');
|
|
|
|
final maxCount = instantiateCounts.reduce(max);
|
|
for (int i = 0; i < maxCount; i++) {
|
|
output.write('''
|
|
|
|
class C$i {}
|
|
''');
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
final dartFilePath = path.join(
|
|
path.dirname(Platform.script.path), 'dart', '$benchmarkName.dart');
|
|
final dartSink = File(dartFilePath).openWrite();
|
|
generateBenchmarkClassesAndUtilities(dartSink, nnbd: true);
|
|
dartSink..flush();
|
|
|
|
final dart2FilePath = path.join(
|
|
path.dirname(Platform.script.path), 'dart2', '$benchmarkName.dart');
|
|
final dart2Sink = File(dart2FilePath).openWrite();
|
|
generateBenchmarkClassesAndUtilities(dart2Sink, nnbd: false);
|
|
dart2Sink..flush();
|
|
}
|