Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[web] Profile text layout and forward data to macrobenchmarks #17276

Merged
merged 3 commits into from
Mar 26, 2020

Conversation

mdebbar
Copy link
Contributor

@mdebbar mdebbar commented Mar 23, 2020

This will allow web benchmarks to capture granular performance metrics. For example, one benchmark could run the gallery app, then receive and accumulate all the "text_layout" numbers.

@mdebbar mdebbar added the platform-web Code specifically for the web engine label Mar 23, 2020
@mdebbar mdebbar requested review from yjbanov and ferhatb March 23, 2020 21:03
@mdebbar mdebbar self-assigned this Mar 23, 2020
///
/// To use the [Profiler]:
///
/// 1. Enable the `FLUTTER_WEB_ENABLE_PROFILING` flag.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: technically it's not a flag, but an environment variable that can be set to "true".

///
/// 1. Enable the `FLUTTER_WEB_ENABLE_PROFILING` flag.
///
/// 2. Using js interop, assign a listener function to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: JS

if (Profiler._instance == null) {
Profiler._instance = Profiler._();
}
return Profiler._instance;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above 4 lines can be reduced to return Profiler._instance ??= Profiler._()


/// Used to send benchmark data to whoever is listening to them.
void benchmark(String name, num value) {
if (!isBenchmarkMode) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move into a shared function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about doing this initially, but decided it may not tree-shake well when I move the throw into a function. But now that tree-shaking is out of the picture anyway, I think it's reasonable to put this logic in a shared function.

_measurementResult = _measurementService.measure(this, constraints);
if (Profiler.isBenchmarkMode) {
Profiler.instance.benchmark('text_layout', stopwatch.elapsedMicroseconds);
stopwatch.stop();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For better accuracy I think you want to stop before sending the number.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think stopwatch.elapsedMicroseconds is being read before calling Profiler.instance.benchmark(). Nevertheless, I'll move the stop to be above :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you're right. I think you can just not call stop at all, although somehow seeing the call to stop gives me more confidence about what's being measured :)

if (!isBenchmarkMode) {
throw Exception(
'Cannot use Profiler unless benchmark mode is enabled. '
'You can enable it by using the FLUTTER_WEB_ENABLE_PROFILING flag.',
Copy link
Contributor

@yjbanov yjbanov Mar 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this message I would also refer to it as "environment variable" ("flag" reads too much like a command-line option)

@ferhatb
Copy link
Contributor

ferhatb commented Mar 24, 2020

Still needs dartfmt and see canvaskit failure.

@mdebbar
Copy link
Contributor Author

mdebbar commented Mar 26, 2020

Mac and Fuchsia failures are unrelated.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes platform-web Code specifically for the web engine
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants