Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Almost a full second of first-frame jank when resuming app on macos with automatic graphics switching enabled #116499

Open
iCodeSometime opened this issue Dec 5, 2022 · 4 comments
Labels
a: desktop Running on desktop c: performance Relates to speed or footprint issues (see "perf:" labels) found in release: 3.3 Found to occur in 3.3 found in release: 3.7 Found to occur in 3.7 has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list perf: energy Performance issues related to energy use (power, watts) platform-mac Building on or for macOS specifically team-desktop Owned by Desktop platforms team triaged-desktop Triaged by Desktop platforms team

Comments

@iCodeSometime
Copy link

iCodeSometime commented Dec 5, 2022

Details

Example app:

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Jank Demo',
      home: ListView.builder(
        itemBuilder: (context, index) => Text(
          index.toString(),
        ),
      ),
    );
  }
}

Setup:
Ensure "Automatic graphics switching" is enabled in MacOS battery preferences (it is by default)

Reproduction steps:
Run the app with flutter run --profile (in the attached traces, I also used --trace-skia)
Open flutter dev tools
Maximize the app
Switch to flutter dev tools via three fingered swipe
View a trace (it seems like there must be some activity happening while the flutter app is in the background, but it certainly doesn't have to be flutter dev tools)
Switch back to the flutter app
Switch back to flutter dev tools and view the frame with jank
(repeat as desired)

Expected result:
The first frame upon switching to the flutter app does not have jank

Actual result:
The first frame takes 950+ms, with the bulk of the time taken up by FlutterCompositorCreateBackingStore

As suggested in #99846, I tried setting enabling NSSupportsAutomaticGraphicsSwitching in macos/Runner/info.plist, but it had no effect.

In the attached trace:
Starting at frame 9, each frame represents switching to the flutter app.
The frames that are under 17ms represent times I switched away from the app but switched back to it before doing much in any other app.
The frames that are over 900ms represent times I did something in another app in between - such as loading a new trace in dart dev tools

dart_devtools_2022-12-04_23_51_03.813.json.zip

Target Platform: MacOS (x86)
Target OS version/browser: 12.5
Devices: 16 inch 2019 macbook pro

Logs

Logs

Analyzing resume_jank.dart...
No issues found! (ran in 1.1s)

[✓] Flutter (Channel master, 3.7.0-2.0.pre.38, on macOS 12.5 21G72 darwin-x64, locale en-US)
• Flutter version 3.7.0-2.0.pre.38 on channel master at /usr/local/Caskroom/flutter/2.10.2/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 18534a8 (7 hours ago), 2022-12-04 17:44:35 -0500
• Engine revision 359a0a979a
• Dart version 2.19.0 (build 2.19.0-444.0.dev)
• DevTools version 2.20.0

[✗] Android toolchain - develop for Android devices
✗ Unable to locate Android SDK.
Install Android Studio from: https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
If the Android SDK has been installed to a custom location, please use
flutter config --android-sdk to update to that location.

[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14B47b
• CocoaPods version 1.11.3

[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio (not installed)
• Android Studio not found; download from https://developer.android.com/studio/index.html
(or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).

[✓] VS Code (version 1.73.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.54.0

[✓] Connected device (2 available)
• macOS (desktop) • macos • darwin-x64 • macOS 12.5 21G72 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 108.0.5359.94

[✓] HTTP Host Availability
• All required HTTP hosts are available

! Doctor found issues in 2 categories.

@iCodeSometime iCodeSometime added the from: performance template Issues created via a performance issue template label Dec 5, 2022
@iCodeSometime
Copy link
Author

Update: if NSSupportsAutomaticGraphicsSwitching is enabled, I am able to reproduce the 950ms+ frames even without switching away from the app.

@darshankawar darshankawar added in triage Presently being triaged by the triage team and removed from: performance template Issues created via a performance issue template labels Dec 5, 2022
@darshankawar
Copy link
Member

Thanks for the detailed report. I tried the same using latest versions and do see a spike in flutter frame rate as below:

Screenshot 2022-12-06 at 11 56 40 AM

stable, master flutter doctor -v
[✓] Flutter (Channel stable, 3.3.9, on macOS 12.2.1 21D62 darwin-x64, locale
    en-GB)
    • Flutter version 3.3.9 on channel stable at
      /Users/dhs/documents/fluttersdk/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b8f7f1f986 (12 days ago), 2022-11-23 06:43:51 +0900
    • Engine revision 8f2221fbef
    • Dart version 2.18.5
    • DevTools version 2.15.0

[!] Xcode - develop for iOS and macOS (Xcode 12.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    ! Flutter recommends a minimum Xcode version of 13.
      Download the latest version or update via the Mac App Store.
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] VS Code (version 1.62.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.21.0

[✓] Connected device (5 available)
    • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
    • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
      ios            • iOS 14.4.1 18D61
    • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    • macOS (desktop)            • macos                                    •
      darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
    • Chrome (web)               • chrome                                   •
      web-javascript • Google Chrome 98.0.4758.80

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

[!] Flutter (Channel master, 3.7.0-3.0.pre.33, on macOS 12.2.1 21D62 darwin-x64,
    locale en-GB)
    • Flutter version 3.7.0-3.0.pre.33 on channel master at
      /Users/dhs/documents/fluttersdk/flutter
    ! Warning: `flutter` on your path resolves to
      /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside
      your current Flutter SDK checkout at
      /Users/dhs/documents/fluttersdk/flutter. Consider adding
      /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path.
    ! Warning: `dart` on your path resolves to
      /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your
      current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter.
      Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front
      of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5201856805 (2 hours ago), 2022-12-05 18:27:21 -0800
    • Engine revision a309d239c4
    • Dart version 2.19.0 (build 2.19.0-463.0.dev)
    • DevTools version 2.20.0
    • If those were intentional, you can disregard the above warnings; however
      it is recommended to use "git" directly to perform update checks and
      upgrades.


[!] Xcode - develop for iOS and macOS (Xcode 12.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    ! Flutter recommends a minimum Xcode version of 13.
      Download the latest version or update via the Mac App Store.
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] VS Code (version 1.62.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.21.0

[✓] Connected device (5 available)
    • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
    • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
      ios            • iOS 14.4.1 18D61
    • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    • macOS (desktop)            • macos                                    •
      darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
    • Chrome (web)               • chrome                                   •
      web-javascript • Google Chrome 98.0.4758.80

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.



@darshankawar darshankawar added c: performance Relates to speed or footprint issues (see "perf:" labels) has reproducible steps The issue has been confirmed reproducible and is ready to work on found in release: 3.3 Found to occur in 3.3 found in release: 3.7 Found to occur in 3.7 platform-mac Building on or for macOS specifically a: desktop Running on desktop perf: energy Performance issues related to energy use (power, watts) and removed in triage Presently being triaged by the triage team labels Dec 6, 2022
@gspencergoog
Copy link
Contributor

cc @cbracken @chinmaygarde

Might be something to consider for Impeller. This appears to be only relevant for Intel Macbooks, not for Apple silicon.

@gspencergoog gspencergoog added the P2 Important issues not at the top of the work list label Dec 8, 2022
@iCodeSometime
Copy link
Author

Thanks. Good to know it doesn't affect the latest hardware, at least

@flutter-triage-bot flutter-triage-bot bot added team-desktop Owned by Desktop platforms team triaged-desktop Triaged by Desktop platforms team labels Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: desktop Running on desktop c: performance Relates to speed or footprint issues (see "perf:" labels) found in release: 3.3 Found to occur in 3.3 found in release: 3.7 Found to occur in 3.7 has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list perf: energy Performance issues related to energy use (power, watts) platform-mac Building on or for macOS specifically team-desktop Owned by Desktop platforms team triaged-desktop Triaged by Desktop platforms team
Projects
None yet
Development

No branches or pull requests

3 participants