Reland "Migrate benchmarks to package:web" (#128266)
This attempts to reland https://github.com/flutter/flutter/pull/126848 This was reverted because it made some unexpected changes to our perf measurements. After landing https://github.com/flutter/flutter/pull/127900, we have much less noise in our benchmarks, so I'd like to reland this and see if there is still a significant measurement difference.
This commit is contained in:
@@ -2,10 +2,12 @@
|
||||
// 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_interop';
|
||||
import 'dart:typed_data';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:web/web.dart' as web;
|
||||
|
||||
import 'recorder.dart';
|
||||
|
||||
// Measures the performance of image decoding.
|
||||
@@ -43,8 +45,11 @@ class BenchImageDecoding extends RawRecorder {
|
||||
return;
|
||||
}
|
||||
for (final String imageUrl in _imageUrls) {
|
||||
final html.Body image = await html.window.fetch(imageUrl) as html.Body;
|
||||
_imageData.add((await image.arrayBuffer() as ByteBuffer).asUint8List());
|
||||
final Future<JSAny?> fetchFuture = web.window.fetch(imageUrl.toJS).toDart;
|
||||
final web.Body image = (await fetchFuture)! as web.Body;
|
||||
final Future<JSAny?> imageFuture = image.arrayBuffer().toDart;
|
||||
final JSArrayBuffer imageBuffer = (await imageFuture)! as JSArrayBuffer;
|
||||
_imageData.add(imageBuffer.toDart.asUint8List());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,11 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:html' as html;
|
||||
import 'dart:js_interop';
|
||||
import 'dart:ui_web' as ui_web;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:web/web.dart' as web;
|
||||
|
||||
import 'recorder.dart';
|
||||
|
||||
@@ -14,16 +15,17 @@ const String benchmarkViewType = 'benchmark_element';
|
||||
|
||||
void _registerFactory() {
|
||||
ui_web.platformViewRegistry.registerViewFactory(benchmarkViewType, (int viewId) {
|
||||
final html.Element htmlElement = html.DivElement();
|
||||
htmlElement.id = '${benchmarkViewType}_$viewId';
|
||||
htmlElement.innerText = 'Google';
|
||||
final web.HTMLElement htmlElement =
|
||||
web.document.createElement('div'.toJS) as web.HTMLDivElement;
|
||||
htmlElement.id = '${benchmarkViewType}_$viewId'.toJS;
|
||||
htmlElement.innerText = 'Google'.toJS;
|
||||
htmlElement.style
|
||||
..width = '100%'
|
||||
..height = '100%'
|
||||
..color = 'black'
|
||||
..backgroundColor = 'rgba(0, 255, 0, .5)'
|
||||
..textAlign = 'center'
|
||||
..border = '1px solid black';
|
||||
..setProperty('width'.toJS, '100%'.toJS)
|
||||
..setProperty('height'.toJS, '100%'.toJS)
|
||||
..setProperty('color'.toJS, 'black'.toJS)
|
||||
..setProperty('backgroundColor'.toJS, 'rgba(0, 255, 0, .5)'.toJS)
|
||||
..setProperty('textAlign'.toJS, 'center'.toJS)
|
||||
..setProperty('border'.toJS, '1px solid black'.toJS);
|
||||
return htmlElement;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,8 +3,11 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:html' as html;
|
||||
import 'dart:js_util' as js_util;
|
||||
import 'dart:js_interop';
|
||||
// The analyzer currently thinks `js_interop_unsafe` is unused, but it is used
|
||||
// for `JSObject.[]=`.
|
||||
// ignore: unused_import
|
||||
import 'dart:js_interop_unsafe';
|
||||
import 'dart:math' as math;
|
||||
import 'dart:ui';
|
||||
|
||||
@@ -15,6 +18,7 @@ import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:web/web.dart' as web;
|
||||
|
||||
/// The default number of samples from warm-up iterations.
|
||||
///
|
||||
@@ -1254,8 +1258,7 @@ void startMeasureFrame(Profile profile) {
|
||||
|
||||
if (!profile.isWarmingUp) {
|
||||
// Tell the browser to mark the beginning of the frame.
|
||||
html.window.performance.mark('measured_frame_start#$_currentFrameNumber');
|
||||
|
||||
web.window.performance.mark('measured_frame_start#$_currentFrameNumber'.toJS);
|
||||
_isMeasuringFrame = true;
|
||||
}
|
||||
}
|
||||
@@ -1277,11 +1280,11 @@ void endMeasureFrame() {
|
||||
|
||||
if (_isMeasuringFrame) {
|
||||
// Tell the browser to mark the end of the frame, and measure the duration.
|
||||
html.window.performance.mark('measured_frame_end#$_currentFrameNumber');
|
||||
html.window.performance.measure(
|
||||
'measured_frame',
|
||||
'measured_frame_start#$_currentFrameNumber',
|
||||
'measured_frame_end#$_currentFrameNumber',
|
||||
web.window.performance.mark('measured_frame_end#$_currentFrameNumber'.toJS);
|
||||
web.window.performance.measure(
|
||||
'measured_frame'.toJS,
|
||||
'measured_frame_start#$_currentFrameNumber'.toJS,
|
||||
'measured_frame_end#$_currentFrameNumber'.toJS,
|
||||
);
|
||||
|
||||
// Increment the current frame number.
|
||||
@@ -1311,9 +1314,11 @@ void registerEngineBenchmarkValueListener(String name, EngineBenchmarkValueListe
|
||||
|
||||
if (_engineBenchmarkListeners.isEmpty) {
|
||||
// The first listener is being registered. Register the global listener.
|
||||
js_util.setProperty(html.window, '_flutter_internal_on_benchmark', _dispatchEngineBenchmarkValue);
|
||||
web.window['_flutter_internal_on_benchmark'.toJS] =
|
||||
// Upcast to [Object] to export.
|
||||
// ignore: unnecessary_cast
|
||||
(_dispatchEngineBenchmarkValue as Object).toJS;
|
||||
}
|
||||
|
||||
_engineBenchmarkListeners[name] = listener;
|
||||
}
|
||||
|
||||
@@ -1321,8 +1326,9 @@ void registerEngineBenchmarkValueListener(String name, EngineBenchmarkValueListe
|
||||
void stopListeningToEngineBenchmarkValues(String name) {
|
||||
_engineBenchmarkListeners.remove(name);
|
||||
if (_engineBenchmarkListeners.isEmpty) {
|
||||
|
||||
// The last listener unregistered. Remove the global listener.
|
||||
js_util.setProperty(html.window, '_flutter_internal_on_benchmark', null);
|
||||
web.window['_flutter_internal_on_benchmark'.toJS] = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user