flutter / devtools

Performance tools for Flutter
https://flutter.dev/docs/development/tools/devtools/
BSD 3-Clause "New" or "Revised" License
1.58k stars 324 forks source link

[devtools]blocked main thread events are not shown in performance overlay or performance monitoring tools #4508

Open peet0r opened 2 years ago

peet0r commented 2 years ago

Issue :

  1. A blocked main thread does not trigger any warnings in default performance monitoring utilities provided by Flutter.

Overview:

When an application blocks the main thread with a computation heavy operation, the user has a fully frozen screen. When the computation is completed and the main thread is unblocked, the app returns to the normal responsive state (nothing shocking here).

This "unresponsive" state is easy to detect when running/testing the application with a human in the loop. However, when using the provided programmatic testing toolchain, this "unresponsive" state does not trigger any issues on performance tests using the traceAction, tracePerformance or any TimelineSummary based diagnostics. This behavior is present in the web based performance tooling and the VSCode tooling as well.

Example:

I have a small project outlining my understanding of my issue here.

Things to note:

maheshj01 commented 2 years ago

Hi @peet0r, Thanks for filing the issue. I am able to reproduce the issue on the latest stable and the master channel. The main thread getting blocked doesn't seem to be reported to the dev tools.

The main thread unbocks at 00:17 and the tap events are executed but the blocked frames are not reported

https://user-images.githubusercontent.com/31410839/184625691-999b2498-1faa-4717-8408-f98ffe58a8da.mov

performance overlay doesn't show the blocking frames

image

This issue also reproduces with other platforms (verified on Android) But is more easily reproducible with MacOS as it gets blocked for a longer duration as compared to mobile devices.

flutter doctor -v (mac) ``` [✓] Flutter (Channel stable, 3.0.5, on macOS 12.4 21F79 darwin-arm, locale en-IN) • Flutter version 3.0.5 at /Users/mahesh/Documents/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision f1875d570e (5 days ago), 2022-07-13 11:24:16 -0700 • Engine revision e85ea0e79c • Dart version 2.17.6 • DevTools version 2.12.2 [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc4) • Android SDK at /Users/mahesh/Library/Android/sdk • Platform android-32, build-tools 33.0.0-rc4 • ANDROID_HOME = /Users/mahesh/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1) • Xcode at /Applications/Xcode.app/Contents/Developer • CocoaPods version 1.11.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2021.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840) [✓] IntelliJ IDEA Community Edition (version 2021.2.1) • IntelliJ at /Applications/IntelliJ IDEA CE.app • Flutter plugin version 61.2.4 • Dart plugin version 212.5080.8 [✓] VS Code (version 1.67.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.44.0 [✓] Connected device (3 available) • sdk gphone arm64 (mobile) • emulator-5554 • android-arm64 • Android 11 (API 30) (emulator) • macOS (desktop) • macos • darwin-arm64 • macOS 12.4 21F79 darwin-arm • Chrome (web) • chrome • web-javascript • Google Chrome 103.0.5060.114 [✓] HTTP Host Availability • All required HTTP hosts are available • No issues found! ``` ``` [✓] Flutter (Channel master, 3.1.0-0.0.pre.2186, on macOS 12.4 21F79 darwin-arm, locale en-IN) • Flutter version 3.1.0-0.0.pre.2186 on channel master at /Users/mahesh/Documents/flutter_master • Upstream repository https://github.com/flutter/flutter.git • Framework revision 458c7b9c65 (5 days ago), 2022-08-10 03:19:07 -0400 • Engine revision 75e17f1a6f • Dart version 2.19.0 (build 2.19.0-81.0.dev) • DevTools version 2.16.0 [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc4) • Android SDK at /Users/mahesh/Library/Android/sdk • Platform android-32, build-tools 33.0.0-rc4 • ANDROID_HOME = /Users/mahesh/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 13C100 • CocoaPods version 1.11.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2021.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840) [✓] IntelliJ IDEA Community Edition (version 2021.2.1) • IntelliJ at /Applications/IntelliJ IDEA CE.app • Flutter plugin version 61.2.4 • Dart plugin version 212.5080.8 [✓] VS Code (version 1.69.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.46.0 [✓] Connected device (2 available) • macOS (desktop) • macos • darwin-arm64 • macOS 12.4 21F79 darwin-arm • Chrome (web) • chrome • web-javascript • Google Chrome 104.0.5112.79 [✓] HTTP Host Availability • All required HTTP hosts are available • No issues found! ```
peet0r commented 2 years ago

One thing that I was not clear from the original post: The fps reporting will not catch the blocked main thread because the blocking function does not trigger a redraw. This is logically consistent with the documentation around widget behavior and the performance monitor tooling, but leaves a test coverage gap. Naively, I expected "Performance Monitor" to include detection of a frozen UI thread, but I was assuming a lot and we all know what that leads to...

The current work around for this issue is a "Watchdog" that expects to be reset every 16ms+variance (60fps). The reset function is called via the Ticker class. This watchdog lives in a separate isolate and records timing statistics to a file for use by CI. There are plans to move this watchdog into our custom embedder, but we wanted to get any insight from the Flutter team/community regarding detection of frozen application UI.

darshankawar commented 2 years ago

/cc @kenzieschmoll Should this be transferred to flutter/devtools repo instead ?

kenzieschmoll commented 2 years ago

related to https://github.com/flutter/devtools/issues/4479