[web] benchmark and optimize defaultTargetPlatform (#75037)
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
// 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 'package:flutter/foundation.dart';
|
||||
|
||||
import 'recorder.dart';
|
||||
|
||||
/// Benchmarks the performance of the [defaultTargetPlatform] getter.
|
||||
///
|
||||
/// The getter relies on the expensive `window.matchMedia` and if not properly
|
||||
/// cached can cause performance issues.
|
||||
class BenchDefaultTargetPlatform extends RawRecorder {
|
||||
BenchDefaultTargetPlatform() : super(name: benchmarkName);
|
||||
|
||||
static const String benchmarkName = 'default_target_platform';
|
||||
|
||||
/// A dummy counter just to make sure the compiler doesn't inline the
|
||||
/// benchmark and make it a no-op.
|
||||
int counter = 0;
|
||||
|
||||
@override
|
||||
void body(Profile profile) {
|
||||
profile.record('runtime', () {
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
counter += defaultTargetPlatform.index;
|
||||
}
|
||||
}, reported: true);
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import 'src/web/bench_build_material_checkbox.dart';
|
||||
import 'src/web/bench_card_infinite_scroll.dart';
|
||||
import 'src/web/bench_child_layers.dart';
|
||||
import 'src/web/bench_clipped_out_pictures.dart';
|
||||
import 'src/web/bench_default_target_platform.dart';
|
||||
import 'src/web/bench_draw_rect.dart';
|
||||
import 'src/web/bench_dynamic_clip_on_static_picture.dart';
|
||||
import 'src/web/bench_mouse_region_grid_hover.dart';
|
||||
@@ -37,6 +38,7 @@ const bool isCanvasKit = bool.fromEnvironment('FLUTTER_WEB_USE_SKIA', defaultVal
|
||||
/// When adding a new benchmark, add it to this map. Make sure that the name
|
||||
/// of your benchmark is unique.
|
||||
final Map<String, RecorderFactory> benchmarks = <String, RecorderFactory>{
|
||||
BenchDefaultTargetPlatform.benchmarkName: () => BenchDefaultTargetPlatform(),
|
||||
BenchBuildImage.benchmarkName: () => BenchBuildImage(),
|
||||
BenchCardInfiniteScroll.benchmarkName: () => BenchCardInfiniteScroll.forward(),
|
||||
BenchCardInfiniteScroll.benchmarkNameBackward: () => BenchCardInfiniteScroll.backward(),
|
||||
|
||||
Reference in New Issue
Block a user