Repository: flutter
Issue: Janky scrolling on iOS when resuming from background/presenting an Add2App ViewController
Labels: platform-ios,engine,c: performance,a: existing-apps,has reproducible steps,P2,found in release: 2.0,found in release: 2.1,team-ios,triaged-ios

<!-- Thank you for using Flutter!

     If you are looking for support, please check out our documentation
     or consider asking a question on Stack Overflow:
      * https://flutter.dev/
      * https://api.flutter.dev/
      * https://stackoverflow.com/questions/tagged/flutter?sort=frequent

     If you have found a performance problem, then fill out the template below.
     Please read our guide to filing a bug first: https://flutter.dev/docs/resources/bug-reports
-->

## Details
I'm experiencing a jank issue on current Stable (2.0.4) on my iPhone 12 mini when running on iOS 14.4.

It looks closely related to this one:
https://github.com/flutter/flutter/issues/40042

I can easily reproduce it when scrolling down the list that I see in the current Reflectly app right after resuming the app from background, or by scrolling down the Stadia app paywall.

Another way to reproduce is this one:
- Paste this code inside a basic template app:
```dart
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Expanded(
              child: ListView(
                children: List.generate(100, (i) => i)
                    .map(
                      (e) => Container(
                        color: e.isEven ? Colors.red : Colors.lightBlue,
                        height: e.isEven ? 200 : 300,
                        width: double.infinity,
                      ),
                    )
                    .toList(),
              ),
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
            TextButton(
              onPressed: _incrementCounter,
              child: Text('Add'),
            ),
          ],
        ),
      ),
    );
  }
```
- Put the app in background
- Try to scroll the list as soon as the app is in foreground again

This issue is also really noticeable in Add2App because it doesn't happen only when app is resumed from background but also (even if in a slightly less impactful way) when new FlutterViewControllers are pushed/presented (even with new lightweight engines). It looks like this weird behaviour could be tied to something that happens right after the viewDidAppear call inside the FlutterViewController.

The behaviour is even more peculiar because when screen recording is active everything always runs butter-smooth.

<!--
1.  Please tell us exactly how to reproduce the problem you are running into.

2.  Please attach a small application (ideally just one main.dart file) that
     reproduces the problem. You could use https://gist.github.com/ for this.

3.  Switch flutter to master channel and run this app on a physical device
     using profile mode with Skia tracing enabled, as follows:
       flutter channel master
       flutter run --profile --trace-skia

     The bleeding edge master channel is encouraged here because Flutter is
     constantly fixing bugs and improving its performance. Your problem in an
     older Flutter version may have already been solved in the master channel.

4.  Record a video of the performance issue using another phone so we
     can have an intuitive understanding of what happened. Don’t use
     "adb screenrecord", as that affects the performance of the profile run.

5.  Open Observatory and save a timeline trace of the performance issue
     so we know which functions might be causing it. See "How to Collect
     and Read Timeline Traces" on this blog post:
       https://medium.com/flutter/profiling-flutter-applications-using-the-timeline-a1a434964af3#a499
     Make sure the performance overlay is turned OFF when recording the
     trace as that may affect the performance of the profile run.
     (Pressing ‘P’ on the command line toggles the overlay.)
-->

<!--
     Please tell us which target platform(s) the problem occurs (Android / iOS / Web / macOS / Linux / Windows)
     Which target OS version, for Web, browser, is the test system running?
     Does the problem occur on emulator/simulator as well as on physical devices?
-->

**Target Platform:** iOS
**Target OS version/browser:** 14.4.x
**Devices:** iPhone

I've managed to perform a profile-run both with screen recording active and not active (and --trace-skia flag).
in the first case you see that the frames timings are constantly below 16ms.
in the second one you can observe that for ~half of the trace, the raster thread is unable to keep the pace of the rendering, but after a while it goes back to normal (and no jank is observed anymore)

https://github.com/flutter/flutter/files/6217423/on_resume_jank.zip

<!-- Finally, paste the output of running `flutter doctor -v` here, with your device plugged in. -->

```
[✓] Flutter (Channel unknown, 2.0.4, on macOS 11.2.3 20D91 darwin-arm, locale it)
    • Flutter version 2.0.4 at /Users/*/Flutter/flutter
    • Framework revision b1395592de (12 days ago), 2021-04-01 14:25:01 -0700
    • Engine revision 2dce47073a
    • Dart version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at  /Users/*/Library/Android/sdk
    • Platform android-30, build-tools 30.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.4, Build version 12D4e
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
    • 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 1.8.0_242-release-1644-b3-6915495)

[✓] IntelliJ IDEA Community Edition (version 2021.1)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 55.0.5
    • Dart plugin version 211.6693.108

[✓] VS Code (version 1.55.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (3 available)
    • iPhone 12 mini (mobile) • 00008101-001514DA3C82001E • ios            • iOS 14.4
    • macOS (desktop)         • macos                     • darwin-arm64   • macOS 11.2.3 20D91 darwin-arm
    • Chrome (web)            • chrome                    • web-javascript • Google Chrome 89.0.4389.114
```