Unverified Commit c2f6a3af authored by Mouad Debbar's avatar Mouad Debbar Committed by GitHub

[web] Stop using web experiments in benchmarks (#94739)

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