Add asset manifest parsing benchmark (#112836)
This commit is contained in:
parent
abca8976e6
commit
eec8d9d9cc
@ -0,0 +1,42 @@
|
|||||||
|
// Copyright 2014 The Flutter Authors. 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:convert';
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/services.dart' show PlatformAssetBundle;
|
||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
|
||||||
|
import '../common.dart';
|
||||||
|
|
||||||
|
const int _kNumIterations = 1000;
|
||||||
|
|
||||||
|
void main() async {
|
||||||
|
assert(false, "Don't run benchmarks in debug mode! Use 'flutter run --release'.");
|
||||||
|
|
||||||
|
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
|
||||||
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
final Stopwatch watch = Stopwatch();
|
||||||
|
final PlatformAssetBundle bundle = PlatformAssetBundle();
|
||||||
|
|
||||||
|
final ByteData assetManifestBytes = await bundle.load('money_asset_manifest.json');
|
||||||
|
watch.start();
|
||||||
|
for (int i = 0; i < _kNumIterations; i++) {
|
||||||
|
bundle.clear();
|
||||||
|
final String json = utf8.decode(assetManifestBytes.buffer.asUint8List());
|
||||||
|
// This is a test, so we don't need to worry about this rule.
|
||||||
|
// ignore: invalid_use_of_visible_for_testing_member
|
||||||
|
await AssetImage.manifestParser(json);
|
||||||
|
}
|
||||||
|
watch.stop();
|
||||||
|
|
||||||
|
printer.addResult(
|
||||||
|
description: 'Load and Parse Large Asset Manifest',
|
||||||
|
value: watch.elapsedMilliseconds.toDouble(),
|
||||||
|
unit: 'ms',
|
||||||
|
name: 'load_and_parse_large_asset_manifest',
|
||||||
|
);
|
||||||
|
|
||||||
|
printer.printToStdout();
|
||||||
|
}
|
1
dev/benchmarks/microbenchmarks/money_asset_manifest.json
Normal file
1
dev/benchmarks/microbenchmarks/money_asset_manifest.json
Normal file
File diff suppressed because one or more lines are too long
@ -70,6 +70,7 @@ dependencies:
|
|||||||
flutter:
|
flutter:
|
||||||
uses-material-design: true
|
uses-material-design: true
|
||||||
assets:
|
assets:
|
||||||
|
- money_asset_manifest.json
|
||||||
- packages/flutter_gallery_assets/people/ali_landscape.png
|
- packages/flutter_gallery_assets/people/ali_landscape.png
|
||||||
- packages/flutter_gallery_assets/monochrome/red-square-1024x1024.png
|
- packages/flutter_gallery_assets/monochrome/red-square-1024x1024.png
|
||||||
- packages/flutter_gallery_assets/logos/flutter_white/logo.png
|
- packages/flutter_gallery_assets/logos/flutter_white/logo.png
|
||||||
|
@ -57,6 +57,7 @@ TaskFunction createMicrobenchmarkTask({bool enableImpeller = false}) {
|
|||||||
...await runMicrobench('lib/foundation/standard_message_codec_bench.dart'),
|
...await runMicrobench('lib/foundation/standard_message_codec_bench.dart'),
|
||||||
...await runMicrobench('lib/foundation/standard_method_codec_bench.dart'),
|
...await runMicrobench('lib/foundation/standard_method_codec_bench.dart'),
|
||||||
...await runMicrobench('lib/foundation/timeline_bench.dart'),
|
...await runMicrobench('lib/foundation/timeline_bench.dart'),
|
||||||
|
...await runMicrobench('lib/foundation/decode_and_parse_asset_manifest.dart'),
|
||||||
...await runMicrobench('lib/geometry/matrix_utils_transform_bench.dart'),
|
...await runMicrobench('lib/geometry/matrix_utils_transform_bench.dart'),
|
||||||
...await runMicrobench('lib/geometry/rrect_contains_bench.dart'),
|
...await runMicrobench('lib/geometry/rrect_contains_bench.dart'),
|
||||||
...await runMicrobench('lib/gestures/gesture_detector_bench.dart'),
|
...await runMicrobench('lib/gestures/gesture_detector_bench.dart'),
|
||||||
|
@ -284,7 +284,7 @@ class AssetImage extends AssetBundleImageProvider {
|
|||||||
Completer<AssetBundleImageKey>? completer;
|
Completer<AssetBundleImageKey>? completer;
|
||||||
Future<AssetBundleImageKey>? result;
|
Future<AssetBundleImageKey>? result;
|
||||||
|
|
||||||
chosenBundle.loadStructuredData<Map<String, List<String>>?>(_kAssetManifestFileName, _manifestParser).then<void>(
|
chosenBundle.loadStructuredData<Map<String, List<String>>?>(_kAssetManifestFileName, manifestParser).then<void>(
|
||||||
(Map<String, List<String>>? manifest) {
|
(Map<String, List<String>>? manifest) {
|
||||||
final String chosenName = _chooseVariant(
|
final String chosenName = _chooseVariant(
|
||||||
keyName,
|
keyName,
|
||||||
@ -328,7 +328,9 @@ class AssetImage extends AssetBundleImageProvider {
|
|||||||
return completer.future;
|
return completer.future;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<Map<String, List<String>>?> _manifestParser(String? jsonData) {
|
/// Parses the asset manifest string into a strongly-typed map.
|
||||||
|
@visibleForTesting
|
||||||
|
static Future<Map<String, List<String>>?> manifestParser(String? jsonData) {
|
||||||
if (jsonData == null) {
|
if (jsonData == null) {
|
||||||
return SynchronousFuture<Map<String, List<String>>?>(null);
|
return SynchronousFuture<Map<String, List<String>>?>(null);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user