Skip to content

Commit a946926

Browse files
jensjohaCommit Queue
authored andcommitted
[kernel] BinaryReader takes Uint8List, not List<int>
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 <[email protected]> Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Jens Johansen <[email protected]> Reviewed-by: Morgan :) <[email protected]> Reviewed-by: Srujan Gaddam <[email protected]> Reviewed-by: Alexander Aprelev <[email protected]>
1 parent 90b52f8 commit a946926

File tree

58 files changed

+205
-151
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+205
-151
lines changed

pkg/build_integration/lib/file_system/multi_root.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class MultiRootFileSystemEntity implements FileSystemEntity {
8585
Future<Uint8List> readAsBytes() async => (await delegate).readAsBytes();
8686

8787
@override
88-
Future<List<int>> readAsBytesAsyncIfPossible() async =>
88+
Future<Uint8List> readAsBytesAsyncIfPossible() async =>
8989
(await delegate).readAsBytes();
9090

9191
@override
@@ -109,7 +109,7 @@ class MissingFileSystemEntity implements FileSystemEntity {
109109
Future.error(FileSystemException(uri, 'File not found'));
110110

111111
@override
112-
Future<List<int>> readAsBytesAsyncIfPossible() => readAsBytes();
112+
Future<Uint8List> readAsBytesAsyncIfPossible() => readAsBytes();
113113

114114
@override
115115
Future<String> readAsString() =>

pkg/build_integration/lib/file_system/single_root.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class SingleRootFileSystemEntity implements FileSystemEntity {
7373
Future<Uint8List> readAsBytes() async => delegate.readAsBytes();
7474

7575
@override
76-
Future<List<int>> readAsBytesAsyncIfPossible() async =>
76+
Future<Uint8List> readAsBytesAsyncIfPossible() async =>
7777
delegate.readAsBytesAsyncIfPossible();
7878

7979
@override

pkg/compiler/lib/src/kernel/front_end_adapter.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class _CompilerFileSystemEntity implements fe.FileSystemEntity {
6868
}
6969

7070
@override
71-
Future<List<int>> readAsBytesAsyncIfPossible() => readAsBytes();
71+
Future<Uint8List> readAsBytesAsyncIfPossible() => readAsBytes();
7272

7373
@override
7474
Future<bool> exists() async {

pkg/compiler/lib/src/phase/load_kernel.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ Future<Output?> run(Input input) async {
417417
if (component == null) return null;
418418
if (input.forceSerialization) {
419419
// TODO(johnniwinther): Remove this when #34942 is fixed.
420-
List<int> data = fe.serializeComponent(component);
420+
Uint8List data = fe.serializeComponent(component);
421421
component = ir.Component();
422422
BinaryBuilder(data).readComponent(component);
423423
// Ensure we use the new deserialized entry point library.

pkg/compiler/lib/src/serialization/strategies.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'dart:io';
6+
import 'dart:typed_data';
67

78
import 'package:front_end/src/api_unstable/dart2js.dart' as ir
89
show serializeComponent, ByteSink;
@@ -22,7 +23,7 @@ import 'task.dart';
2223
abstract class SerializationStrategy<T> {
2324
const SerializationStrategy();
2425

25-
List<int> unpackAndSerializeComponent(GlobalTypeInferenceResults results) {
26+
Uint8List unpackAndSerializeComponent(GlobalTypeInferenceResults results) {
2627
JClosedWorld closedWorld = results.closedWorld;
2728
ir.Component component = closedWorld.elementMap.programEnv.mainComponent;
2829
return serializeComponent(component);
@@ -33,11 +34,11 @@ abstract class SerializationStrategy<T> {
3334
CompilerOptions options,
3435
SerializationIndices indices);
3536

36-
List<int> serializeComponent(ir.Component component) {
37+
Uint8List serializeComponent(ir.Component component) {
3738
return ir.serializeComponent(component);
3839
}
3940

40-
ir.Component deserializeComponent(List<int> data) {
41+
ir.Component deserializeComponent(Uint8List data) {
4142
ir.Component component = ir.Component();
4243
BinaryBuilder(data).readComponent(component);
4344
return component;

pkg/compiler/test/serialization/serialization_test_helper.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'dart:io';
6+
import 'dart:typed_data';
67

78
import 'package:compiler/compiler_api.dart' as api;
89
import 'package:compiler/src/commandline_options.dart';
@@ -273,7 +274,7 @@ JClosedWorld cloneClosedWorld(Compiler compiler, JClosedWorld closedWorld,
273274
SerializationStrategy strategy) {
274275
SerializationIndices indices = SerializationIndices();
275276
ir.Component component = closedWorld.elementMap.programEnv.mainComponent;
276-
List<int> irData = strategy.serializeComponent(component);
277+
Uint8List irData = strategy.serializeComponent(component);
277278
final closedWorldData = strategy.serializeClosedWorld(
278279
closedWorld, compiler.options, indices) as List<int>;
279280
print('data size: ${closedWorldData.length}');
@@ -302,7 +303,7 @@ JClosedWorld cloneClosedWorld(Compiler compiler, JClosedWorld closedWorld,
302303
GlobalTypeInferenceResults cloneInferenceResults(Compiler compiler,
303304
GlobalTypeInferenceResults results, SerializationStrategy strategy) {
304305
SerializationIndices indices = SerializationIndices(testMode: true);
305-
List<int> irData = strategy.unpackAndSerializeComponent(results);
306+
Uint8List irData = strategy.unpackAndSerializeComponent(results);
306307
final closedWorldData = strategy.serializeClosedWorld(
307308
results.closedWorld, compiler.options, indices) as List<int>;
308309
ir.Component newComponent = strategy.deserializeComponent(irData);

pkg/dev_compiler/lib/src/kernel/asset_file_system.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class AssetFileSystemEntity implements FileSystemEntity {
9898
}
9999

100100
@override
101-
Future<List<int>> readAsBytesAsyncIfPossible() => readAsBytes();
101+
Future<Uint8List> readAsBytesAsyncIfPossible() => readAsBytes();
102102

103103
@override
104104
Future<String> readAsString() async {

pkg/front_end/lib/src/api_prototype/file_system.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ abstract class FileSystemEntity {
8181
/// If an error occurs while attempting to read the file (e.g. because no such
8282
/// file exists, or the entity is a directory), the future is completed with
8383
/// [FileSystemException].
84-
Future<List<int>> readAsBytesAsyncIfPossible();
84+
Future<Uint8List> readAsBytesAsyncIfPossible();
8585

8686
/// Attempts to access this file system entity as a file and read its contents
8787
/// as a string.

pkg/front_end/lib/src/api_prototype/kernel_generator.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
/// Defines the front-end API for converting source code to Dart Kernel objects.
66
library front_end.kernel_generator;
77

8+
import 'dart:typed_data';
9+
810
import 'package:_fe_analyzer_shared/src/messages/codes.dart'
911
show messageMissingMain, noLength;
1012
import 'package:_fe_analyzer_shared/src/messages/severity.dart' show Severity;
@@ -109,7 +111,7 @@ Future<CompilerResult> kernelForModule(
109111
/// Result object for [kernelForProgram] and [kernelForModule].
110112
abstract class CompilerResult {
111113
/// The generated summary bytes, if it was requested.
112-
List<int>? get summary;
114+
Uint8List? get summary;
113115

114116
/// The generated component, if it was requested.
115117
Component? get component;

pkg/front_end/lib/src/api_prototype/memory_file_system.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class MemoryFileSystemEntity implements FileSystemEntity {
105105

106106
@override
107107
// Coverage-ignore(suite): Not run.
108-
Future<List<int>> readAsBytesAsyncIfPossible() => readAsBytes();
108+
Future<Uint8List> readAsBytesAsyncIfPossible() => readAsBytes();
109109

110110
@override
111111
// Coverage-ignore(suite): Not run.

0 commit comments

Comments
 (0)