Unverified Commit eec8d9d9 authored by Andrew Kolos's avatar Andrew Kolos Committed by GitHub

Add asset manifest parsing benchmark (#112836)

parent abca8976
// 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();
}
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -70,6 +70,7 @@ dependencies:
flutter:
uses-material-design: true
assets:
- money_asset_manifest.json
- packages/flutter_gallery_assets/people/ali_landscape.png
- packages/flutter_gallery_assets/monochrome/red-square-1024x1024.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_method_codec_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/rrect_contains_bench.dart'),
...await runMicrobench('lib/gestures/gesture_detector_bench.dart'),
......
......@@ -284,7 +284,7 @@ class AssetImage extends AssetBundleImageProvider {
Completer<AssetBundleImageKey>? completer;
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) {
final String chosenName = _chooseVariant(
keyName,
......@@ -328,7 +328,9 @@ class AssetImage extends AssetBundleImageProvider {
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) {
return SynchronousFuture<Map<String, List<String>>?>(null);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment