[web] Stop using web experiments in benchmarks (#94739)
This commit is contained in:
parent
1aabe314a9
commit
c2f6a3af91
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:html' as html;
|
||||
import 'dart:js_util' as js_util;
|
||||
import 'dart:math';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
@ -52,59 +50,25 @@ enum _TestMode {
|
||||
/// Uses the HTML rendering backend with the canvas 2D text layout.
|
||||
useCanvasTextLayout,
|
||||
|
||||
/// Uses the HTML rendering backend with the DOM text layout.
|
||||
useDomTextLayout,
|
||||
|
||||
/// Uses CanvasKit for everything.
|
||||
useCanvasKit,
|
||||
}
|
||||
|
||||
/// Sends a platform message to the web engine to enable/disable the usage of
|
||||
/// the canvas-based text measurement implementation.
|
||||
void _setTestMode(_TestMode? mode) {
|
||||
bool? useCanvasText; // null means do not force DOM or canvas, works for CanvasKit
|
||||
switch (mode) {
|
||||
case _TestMode.useDomTextLayout:
|
||||
useCanvasText = false;
|
||||
break;
|
||||
case _TestMode.useCanvasTextLayout:
|
||||
useCanvasText = true;
|
||||
break;
|
||||
case _TestMode.useCanvasKit:
|
||||
case null:
|
||||
// Keep as null.
|
||||
break;
|
||||
}
|
||||
// ignore: implicit_dynamic_function
|
||||
js_util.callMethod(
|
||||
html.window,
|
||||
'_flutter_internal_update_experiment',
|
||||
<dynamic>['useCanvasText', useCanvasText],
|
||||
);
|
||||
}
|
||||
|
||||
/// Repeatedly lays out a paragraph.
|
||||
///
|
||||
/// Creates a different paragraph each time in order to avoid hitting the cache.
|
||||
class BenchTextLayout extends RawRecorder {
|
||||
BenchTextLayout.dom()
|
||||
: _mode = _TestMode.useDomTextLayout, super(name: domBenchmarkName);
|
||||
|
||||
BenchTextLayout.canvas()
|
||||
: _mode = _TestMode.useCanvasTextLayout, super(name: canvasBenchmarkName);
|
||||
: super(name: canvasBenchmarkName);
|
||||
|
||||
BenchTextLayout.canvasKit()
|
||||
: _mode = _TestMode.useCanvasKit, super(name: canvasKitBenchmarkName);
|
||||
: super(name: canvasKitBenchmarkName);
|
||||
|
||||
static const String domBenchmarkName = 'text_dom_layout';
|
||||
static const String canvasBenchmarkName = 'text_canvas_layout';
|
||||
static const String canvasKitBenchmarkName = 'text_canvaskit_layout';
|
||||
|
||||
final ParagraphGenerator generator = ParagraphGenerator();
|
||||
|
||||
/// Whether to use the new canvas-based text measurement implementation.
|
||||
final _TestMode _mode;
|
||||
|
||||
static const String singleLineText = '*** ** ****';
|
||||
static const String multiLineText = '*** ****** **** *** ******** * *** '
|
||||
'******* **** ********** *** ******* '
|
||||
@ -113,8 +77,6 @@ class BenchTextLayout extends RawRecorder {
|
||||
|
||||
@override
|
||||
void body(Profile profile) {
|
||||
_setTestMode(_mode);
|
||||
|
||||
recordParagraphOperations(
|
||||
profile: profile,
|
||||
paragraph: generator.generate(singleLineText),
|
||||
@ -146,8 +108,6 @@ class BenchTextLayout extends RawRecorder {
|
||||
keyPrefix: 'ellipsis',
|
||||
maxWidth: 200.0,
|
||||
);
|
||||
|
||||
_setTestMode(null);
|
||||
}
|
||||
|
||||
void recordParagraphOperations({
|
||||
@ -183,25 +143,17 @@ class BenchTextLayout extends RawRecorder {
|
||||
/// use the same paragraph instance because the layout method will shortcircuit
|
||||
/// in that case.
|
||||
class BenchTextCachedLayout extends RawRecorder {
|
||||
BenchTextCachedLayout.dom()
|
||||
: _mode = _TestMode.useDomTextLayout, super(name: domBenchmarkName);
|
||||
|
||||
BenchTextCachedLayout.canvas()
|
||||
: _mode = _TestMode.useCanvasTextLayout, super(name: canvasBenchmarkName);
|
||||
: super(name: canvasBenchmarkName);
|
||||
|
||||
BenchTextCachedLayout.canvasKit()
|
||||
: _mode = _TestMode.useCanvasKit, super(name: canvasKitBenchmarkName);
|
||||
: super(name: canvasKitBenchmarkName);
|
||||
|
||||
static const String domBenchmarkName = 'text_dom_cached_layout';
|
||||
static const String canvasBenchmarkName = 'text_canvas_cached_layout';
|
||||
static const String canvasKitBenchmarkName = 'text_canvas_kit_cached_layout';
|
||||
|
||||
/// Whether to use the new canvas-based text measurement implementation.
|
||||
final _TestMode _mode;
|
||||
|
||||
@override
|
||||
void body(Profile profile) {
|
||||
_setTestMode(_mode);
|
||||
final ui.ParagraphBuilder builder = ui.ParagraphBuilder(ui.ParagraphStyle(fontFamily: 'sans-serif'))
|
||||
..pushStyle(ui.TextStyle(fontSize: 12.0))
|
||||
..addText(
|
||||
@ -212,7 +164,6 @@ class BenchTextCachedLayout extends RawRecorder {
|
||||
profile.record('layout', () {
|
||||
paragraph.layout(const ui.ParagraphConstraints(width: double.infinity));
|
||||
}, reported: true);
|
||||
_setTestMode(null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -230,8 +181,7 @@ int _counter = 0;
|
||||
class BenchBuildColorsGrid extends WidgetBuildRecorder {
|
||||
BenchBuildColorsGrid.canvas()
|
||||
: _mode = _TestMode.useCanvasTextLayout, super(name: canvasBenchmarkName);
|
||||
BenchBuildColorsGrid.dom()
|
||||
: _mode = _TestMode.useDomTextLayout, super(name: domBenchmarkName);
|
||||
|
||||
BenchBuildColorsGrid.canvasKit()
|
||||
: _mode = _TestMode.useCanvasKit, super(name: canvasKitBenchmarkName);
|
||||
|
||||
@ -240,12 +190,9 @@ class BenchBuildColorsGrid extends WidgetBuildRecorder {
|
||||
/// When tracing is enabled, DOM layout takes longer to complete. This has a
|
||||
/// significant effect on the benchmark since we do a lot of text layout
|
||||
/// operations that trigger synchronous DOM layout.
|
||||
///
|
||||
/// Tracing has a negative effect only in [_TestMode.useDomTextLayout] mode.
|
||||
@override
|
||||
bool get isTracingEnabled => false;
|
||||
|
||||
static const String domBenchmarkName = 'text_dom_color_grid';
|
||||
static const String canvasBenchmarkName = 'text_canvas_color_grid';
|
||||
static const String canvasKitBenchmarkName = 'text_canvas_kit_color_grid';
|
||||
|
||||
@ -256,7 +203,6 @@ class BenchBuildColorsGrid extends WidgetBuildRecorder {
|
||||
|
||||
@override
|
||||
Future<void> setUpAll() async {
|
||||
_setTestMode(_mode);
|
||||
registerEngineBenchmarkValueListener('text_layout', (num value) {
|
||||
_textLayoutMicros += value;
|
||||
});
|
||||
@ -264,7 +210,6 @@ class BenchBuildColorsGrid extends WidgetBuildRecorder {
|
||||
|
||||
@override
|
||||
Future<void> tearDownAll() async {
|
||||
_setTestMode(null);
|
||||
stopListeningToEngineBenchmarkValues('text_layout');
|
||||
}
|
||||
|
||||
|
@ -72,11 +72,8 @@ final Map<String, RecorderFactory> benchmarks = <String, RecorderFactory>{
|
||||
|
||||
// HTML-only benchmarks
|
||||
if (!isCanvasKit) ...<String, RecorderFactory>{
|
||||
BenchTextLayout.domBenchmarkName: () => BenchTextLayout.dom(),
|
||||
BenchTextLayout.canvasBenchmarkName: () => BenchTextLayout.canvas(),
|
||||
BenchTextCachedLayout.domBenchmarkName: () => BenchTextCachedLayout.dom(),
|
||||
BenchTextCachedLayout.canvasBenchmarkName: () => BenchTextCachedLayout.canvas(),
|
||||
BenchBuildColorsGrid.domBenchmarkName: () => BenchBuildColorsGrid.dom(),
|
||||
BenchBuildColorsGrid.canvasBenchmarkName: () => BenchBuildColorsGrid.canvas(),
|
||||
},
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user