a9469269d7
In AOT this makes reading faster: Output from `out/ReleaseX64/dart pkg/front_end/tool/benchmarker.dart --iterations=10 --snapshot=pkg/front_end/test/kernel_binary_bench.aot.1 --snapshot=pkg/front_end/test/kernel_binary_bench.aot.2 --arguments="--warmups=10" --arguments="--iterations=5" --arguments="AstFromBinaryEager" --arguments="out/ReleaseX64/vm_platform_strong.dill"`: ``` msec task-clock:u: -8.6925% +/- 0.5737% (-167.09 +/- 11.03) page-faults:u: 0.1410% +/- 0.0051% (243.00 +/- 8.71) cycles:u: -10.2918% +/- 0.6161% (-732576747.50 +/- 43853449.16) instructions:u: -14.4988% +/- 0.0004% (-1636799813.90 +/- 39902.18) branch-misses:u: -3.4891% +/- 2.1142% (-1166085.00 +/- 706582.35) seconds time elapsed: -8.7005% +/- 0.5634% (-0.17 +/- 0.01) seconds user: -9.9752% +/- 1.5104% (-0.17 +/- 0.03) ``` Stats running manually (run as e.g. `out/ReleaseX64/dart-sdk/bin/dartaotruntime pkg/front_end/test/kernel_binary_bench.aot.1 --warmups=10 --iterations=5 AstFromBinaryEager out/ReleaseX64/vm_platform_strong.dill`): ``` AstFromBinaryEagerCold: -12.5174% +/- 3.10688% AstFromBinaryEagerWarmup: -8.33675% +/- 2.62433% AstFromBinaryEager: -10.3432% +/- 3.68375% ``` I don't expect there to be much of a change (if any) in JIT as the actual type was in practise always Uint8List anyway. TEST=Existing tests. Change-Id: I86b16ed207343848dee2e376f42598c223bbc48f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393740 Reviewed-by: Mayank Patke <fishythefish@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com> Commit-Queue: Jens Johansen <jensj@google.com> Reviewed-by: Morgan :) <davidmorgan@google.com> Reviewed-by: Srujan Gaddam <srujzs@google.com> Reviewed-by: Alexander Aprelev <aam@google.com>
148 lines
5.1 KiB
Dart
148 lines
5.1 KiB
Dart
// Copyright (c) 2020, 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.
|
|
|
|
import 'dart:typed_data';
|
|
|
|
import 'package:kernel/binary/ast_from_binary.dart';
|
|
|
|
import 'utils.dart';
|
|
|
|
void main() {
|
|
void setCompileMode(Component c, NonNullableByDefaultCompiledMode mode) {
|
|
c.setMainMethodAndMode(null, true, mode);
|
|
}
|
|
|
|
void verifyMode(Component c, NonNullableByDefaultCompiledMode mode) {
|
|
if (c.mode != mode) {
|
|
throw "Serialized and re-read component had change in mode: "
|
|
"Expected $mode got ${c.mode}.";
|
|
}
|
|
}
|
|
|
|
const List<NonNullableByDefaultCompiledMode> modes = const [
|
|
NonNullableByDefaultCompiledMode.Weak,
|
|
NonNullableByDefaultCompiledMode.Strong,
|
|
];
|
|
|
|
int combination = 0;
|
|
for (NonNullableByDefaultCompiledMode c1Mode in modes) {
|
|
for (NonNullableByDefaultCompiledMode c2Mode in modes) {
|
|
combination++;
|
|
print("Checking combination #$combination ("
|
|
"c1Mode: $c1Mode; "
|
|
"c2Mode: $c2Mode; "
|
|
")");
|
|
|
|
// Try individually.
|
|
Uint8List c1Serialized;
|
|
{
|
|
Uri uri = Uri.parse("foo://bar.dart");
|
|
Library lib1 = new Library(uri, fileUri: uri)
|
|
..nonNullableByDefaultCompiledMode = c1Mode;
|
|
Component c1 = new Component(libraries: [lib1]);
|
|
setCompileMode(c1, c1Mode);
|
|
c1Serialized = serializeComponent(c1);
|
|
Component c1RoundTrip = loadComponentFromBytes(c1Serialized);
|
|
verifyMode(c1RoundTrip, c1Mode);
|
|
}
|
|
|
|
Uint8List c2Serialized;
|
|
{
|
|
Uri uri = Uri.parse("foo://baz.dart");
|
|
Library lib2 = new Library(uri, fileUri: uri)
|
|
..nonNullableByDefaultCompiledMode = c2Mode;
|
|
Component c2 = new Component(libraries: [lib2]);
|
|
setCompileMode(c2, c2Mode);
|
|
c2Serialized = serializeComponent(c2);
|
|
Component c2RoundTrip = loadComponentFromBytes(c2Serialized);
|
|
verifyMode(c2RoundTrip, c2Mode);
|
|
}
|
|
|
|
// Try with combined binary.
|
|
try {
|
|
Uint8List combined =
|
|
Uint8List.fromList([...c1Serialized, ...c2Serialized]);
|
|
Component combinedRoundTrip = loadComponentFromBytes(combined);
|
|
verifyMode(combinedRoundTrip, verifyOK(c1Mode, c2Mode));
|
|
print(" -> OK with $c1Mode and $c2Mode");
|
|
} on CompilationModeError catch (e) {
|
|
print(" -> Got $e with $c1Mode and $c2Mode");
|
|
verifyError(c1Mode, c2Mode);
|
|
}
|
|
// Try other order.
|
|
try {
|
|
Uint8List combined =
|
|
Uint8List.fromList([...c2Serialized, ...c1Serialized]);
|
|
Component combinedRoundTrip = loadComponentFromBytes(combined);
|
|
verifyMode(combinedRoundTrip, verifyOK(c1Mode, c2Mode));
|
|
print(" -> OK with $c1Mode and $c2Mode");
|
|
} on CompilationModeError catch (e) {
|
|
print(" -> Got $e with $c1Mode and $c2Mode");
|
|
verifyError(c1Mode, c2Mode);
|
|
}
|
|
|
|
// Try with individual binary, but loaded into same component.
|
|
try {
|
|
Component combinedRoundTrip = loadComponentFromBytes(c1Serialized);
|
|
combinedRoundTrip =
|
|
loadComponentFromBytes(c2Serialized, combinedRoundTrip);
|
|
verifyMode(combinedRoundTrip, verifyOK(c1Mode, c2Mode));
|
|
print(" -> OK with $c1Mode and $c2Mode");
|
|
} on CompilationModeError catch (e) {
|
|
print(" -> Got $e with $c1Mode and $c2Mode");
|
|
verifyError(c1Mode, c2Mode);
|
|
}
|
|
// Try other order.
|
|
try {
|
|
Component combinedRoundTrip = loadComponentFromBytes(c2Serialized);
|
|
combinedRoundTrip =
|
|
loadComponentFromBytes(c1Serialized, combinedRoundTrip);
|
|
verifyMode(combinedRoundTrip, verifyOK(c1Mode, c2Mode));
|
|
print(" -> OK with $c1Mode and $c2Mode");
|
|
} on CompilationModeError catch (e) {
|
|
print(" -> Got $e with $c1Mode and $c2Mode");
|
|
verifyError(c1Mode, c2Mode);
|
|
}
|
|
|
|
// Try with individual binary, but loaded into same component where
|
|
// component initially does not have a mode.
|
|
try {
|
|
Component combinedRoundTrip = new Component();
|
|
combinedRoundTrip =
|
|
loadComponentFromBytes(c1Serialized, combinedRoundTrip);
|
|
combinedRoundTrip =
|
|
loadComponentFromBytes(c2Serialized, combinedRoundTrip);
|
|
verifyMode(combinedRoundTrip, verifyOK(c1Mode, c2Mode));
|
|
print(" -> OK with $c1Mode and $c2Mode");
|
|
} on CompilationModeError catch (e) {
|
|
print(" -> Got $e with $c1Mode and $c2Mode");
|
|
verifyError(c1Mode, c2Mode);
|
|
}
|
|
}
|
|
}
|
|
|
|
print("Done: Everything looks good.");
|
|
}
|
|
|
|
bool isOK(NonNullableByDefaultCompiledMode c1Mode,
|
|
NonNullableByDefaultCompiledMode c2Mode) {
|
|
return c1Mode == c2Mode;
|
|
}
|
|
|
|
NonNullableByDefaultCompiledMode verifyOK(
|
|
NonNullableByDefaultCompiledMode c1Mode,
|
|
NonNullableByDefaultCompiledMode c2Mode) {
|
|
if (isOK(c1Mode, c2Mode)) {
|
|
return c1Mode;
|
|
}
|
|
throw "Not OK combination: $c1Mode and $c2Mode";
|
|
}
|
|
|
|
void verifyError(NonNullableByDefaultCompiledMode c1Mode,
|
|
NonNullableByDefaultCompiledMode c2Mode) {
|
|
if (isOK(c1Mode, c2Mode)) {
|
|
throw "Unexpected error for $c1Mode and $c2Mode";
|
|
}
|
|
}
|