Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Linux Desktop: high CPU usage when running an animation #101591

@fusion44

Description

@fusion44

Hi!

CPU usage goes through the roof when I run a simple animation on Linux Desktop. Please find the minimum sample app below. I ran the same code on a Windows machine where this problem does not occur. I've don't have access to a Mac to test it there.

When running the app with the profiler enabled I've noticed that the FPS is at 60 FPS all the time but visually the animation is quite janky. It only gets better marginally when run in release mode. This might be a clue that the problem occurs when presenting the frame to the screen?

I've verified that the graphics drivers work well on my Linux system by running a the same game on Linux and Windows. They ran at nearly the same FPS.

I've tried both, the stable and master channels with the same results.

All tests are ran on the same machine which is dual booted between Linux / Windows

edit: added more hardware / software info

CPU usage on Linux:

  • Linux with animation: all 8 cores are used between 30-50 %.
    Bildschirmfoto von 2022-04-08 18-32-12

  • Linux, no animation: all 8 cores are used at around 5 %, matching Windows
    Bildschirmfoto von 2022-04-08 18-38-26

  • Linux, with animimation, Vivaldi browser smooth animation, normal CPU usage
    Bildschirmfoto von 2022-04-08 19-09-12

  • Windows, with animation: all 8 cores are used at around 5-10 %
    image

Details

Code to reproduce. This is a standard flutter create project with the counter text replaced with a CircularProgressIndicator()

import 'package:flutter/material.dart';

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

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);



  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: const Center(
        child: CircularProgressIndicator(),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

Target Platform: Linux Desktop
Target OS version/browser: Ubuntu 21.10 (Regolith Linux flavor)
Devices: amd64 platform

image

Logs

Logs
fusion44@fusion44-UM700:~/dev/stuff/bug$ flutter run --profile -v
[  +73 ms] executing: uname -m
[  +37 ms] Exit code 0 from: uname -m
[        ] x86_64
[   +6 ms] executing: [/home/fusion44/snap/flutter/common/flutter/] git -c log.showSignature=false log -n 1 --pretty=format:%H
[   +7 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%H
[        ] c860cba910319332564e1e9d470a17074c1f2dfd
[        ] executing: [/home/fusion44/snap/flutter/common/flutter/] git tag --points-at c860cba910319332564e1e9d470a17074c1f2dfd
[  +17 ms] Exit code 0 from: git tag --points-at c860cba910319332564e1e9d470a17074c1f2dfd
[        ] 2.10.4
[  +13 ms] executing: [/home/fusion44/snap/flutter/common/flutter/] git rev-parse --abbrev-ref --symbolic @{u}
[   +7 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[        ] origin/stable
[        ] executing: [/home/fusion44/snap/flutter/common/flutter/] git ls-remote --get-url origin
[   +7 ms] Exit code 0 from: git ls-remote --get-url origin
[        ] https://github.com/flutter/flutter.git
[  +88 ms] executing: [/home/fusion44/snap/flutter/common/flutter/] git rev-parse --abbrev-ref HEAD
[   +6 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[        ] stable
[  +59 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[   +3 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'WindowsUwpEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[  +60 ms] executing: /home/fusion44/Android/Sdk/platform-tools/adb devices -l
[  +59 ms] List of devices attached
[   +7 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[   +1 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'WindowsUwpEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[   +2 ms] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[ +131 ms] Skipping pub get: version match.
[  +79 ms] Generating /home/fusion44/dev/stuff/bug/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java
[  +97 ms] Launching lib/main.dart on Linux in profile mode...
[  +17 ms] Building Linux application...
[   +8 ms] executing: [build/linux/x64/profile/] cmake -G Ninja -DCMAKE_BUILD_TYPE=Profile -DFLUTTER_TARGET_PLATFORM=linux-x64 /home/fusion44/dev/stuff/bug/linux
[  +42 ms] -- Configuring done
[   +4 ms] -- Generating done
[        ] -- Build files have been written to: /home/fusion44/dev/stuff/bug/build/linux/x64/profile
[   +5 ms] executing: ninja -C build/linux/x64/profile install
[   +8 ms] ninja: Entering directory `build/linux/x64/profile'
[+1944 ms] [1/5] Generating /home/fusion44/dev/stuff/bug/linux/flutter/ephemeral/libflutter_linux_gtk.so, /home/fusion44/dev/stuff/bug/linux/flutter/ephemeral/flutter_linux/fl_basic_message_channel.h, /home/fusion44/dev/stuff/bug/linux/flutter/ephemeral/flutter_linux/fl_binary_codec.h,
/home/fusion44/dev/stuff/bug/linux/flutter/ephemeral/flutter_linux/fl_binary_messenger.h, /home/fusion44/dev/stuff/bug/linux/flutter/ephemeral/flutter_linux/fl_dart_project.h, /home/fusion44/dev/stuff/bug/linux/flutter/ephemeral/flutter_linux/fl_engine.h,
/home/fusion44/dev/stuff/bug/linux/flutter/ephemeral/flutter_linux/fl_json_message_codec.h, /home/fusion44/dev/stuff/bug/linux/flutter/ephemeral/flutter_linux/fl_json_method_codec.h, /home/fusion44/dev/stuff/bug/linux/flutter/ephemeral/flutter_linux/fl_message_codec.h,
/home/fusion44/dev/stuff/bug/linux/flutter/ephemeral/flutter_linux/fl_method_call.h, /home/fusion44/dev/stuff/bug/linux/flutter/ephemeral/flutter_linux/fl_method_channel.h, /home/fusion44/dev/stuff/bug/linux/flutter/ephemeral/flutter_linux/fl_method_codec.h,
/home/fusion44/dev/stuff/bug/linux/flutter/ephemeral/flutter_linux/fl_method_response.h, /home/fusion44/dev/stuff/bug/linux/flutter/ephemeral/flutter_linux/fl_plugin_registrar.h, /home/fusion44/dev/stuff/bug/linux/flutter/ephemeral/flutter_linux/fl_plugin_registry.h,
/home/fusion44/dev/stuff/bug/linux/flutter/ephemeral/flutter_linux/fl_standard_message_codec.h, /home/fusion44/dev/stuff/bug/linux/flutter/ephemeral/flutter_linux/fl_standard_method_codec.h, /home/fusion44/dev/stuff/bug/linux/flutter/ephemeral/flutter_linux/fl_string_codec.h,
/home/fusion44/dev/stuff/bug/linux/flutter/ephemeral/flutter_linux/fl_value.h, /home/fusion44/dev/stuff/bug/linux/flutter/ephemeral/flutter_linux/fl_view.h, /home/fusion44/dev/stuff/bug/linux/flutter/ephemeral/flutter_linux/flutter_linux.h, _phony_
[   +6 ms] [  +65 ms] executing: uname -m
[        ] [  +34 ms] Exit code 0 from: uname -m
[        ] [        ] x86_64
[        ] [   +5 ms] executing: [/home/fusion44/snap/flutter/common/flutter/] git -c log.showSignature=false log -n 1 --pretty=format:%H
[        ] [   +6 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%H
[        ] [        ] c860cba910319332564e1e9d470a17074c1f2dfd
[        ] [        ] executing: [/home/fusion44/snap/flutter/common/flutter/] git tag --points-at c860cba910319332564e1e9d470a17074c1f2dfd
[        ] [  +23 ms] Exit code 0 from: git tag --points-at c860cba910319332564e1e9d470a17074c1f2dfd
[        ] [        ] 2.10.4
[        ] [   +9 ms] executing: [/home/fusion44/snap/flutter/common/flutter/] git rev-parse --abbrev-ref --symbolic @{u}
[        ] [   +6 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[        ] [        ] origin/stable
[        ] [        ] executing: [/home/fusion44/snap/flutter/common/flutter/] git ls-remote --get-url origin
[        ] [   +5 ms] Exit code 0 from: git ls-remote --get-url origin
[        ] [        ] https://github.com/flutter/flutter.git
[        ] [  +54 ms] executing: [/home/fusion44/snap/flutter/common/flutter/] git rev-parse --abbrev-ref HEAD
[        ] [   +4 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[        ] [        ] stable
[        ] [  +49 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] [        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] [        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] [        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[        ] [   +3 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] [        ] Artifact Instance of 'WindowsUwpEngineArtifacts' is not required, skipping update.
[        ] [        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] [        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] [        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] [        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] [        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] [        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[        ] [  +90 ms] Artifact Instance of 'MaterialFonts' is not required, skipping update.
[        ] [        ] Artifact Instance of 'GradleWrapper' is not required, skipping update.
[        ] [        ] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] [        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] [        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] [        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[        ] [        ] Artifact Instance of 'FlutterSdk' is not required, skipping update.
[        ] [        ] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] [        ] Artifact Instance of 'WindowsUwpEngineArtifacts' is not required, skipping update.
[        ] [        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] [   +1 ms] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] [        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] [        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] [        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[        ] [        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] [        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] [        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] [        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] [        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] [        ] Artifact Instance of 'FontSubsetArtifacts' is not required, skipping update.
[        ] [        ] Artifact Instance of 'PubDependencies' is not required, skipping update.
[        ] [  +79 ms] Initializing file store
[        ] [   +8 ms] Done initializing file store
[        ] [  +42 ms] Skipping target: gen_localizations
[        ] [  +10 ms] Skipping target: gen_dart_plugin_registrant
[        ] [ +256 ms] Skipping target: unpack_linux
[        ] [ +306 ms] Skipping target: kernel_snapshot
[        ] [  +30 ms] Skipping target: aot_elf_profile
[        ] [  +28 ms] Skipping target: linux_aot_bundle
[        ] [  +28 ms] Skipping target: profile_bundle_linux-x64_assets
[        ] [        ] Persisting file store
[        ] [   +8 ms] Done persisting file store
[        ] [   +4 ms] build succeeded.
[        ] [   +7 ms] "flutter assemble" took 929ms.
[        ] [   +3 ms] Running shutdown hooks
[        ] [        ] Shutdown hooks complete
[        ] [   +3 ms] exiting with code 0
[ +418 ms] [2/5] Building CXX object CMakeFiles/bug.dir/flutter/generated_plugin_registrant.cc.o
[  +61 ms] [3/5] Building CXX object CMakeFiles/bug.dir/my_application.cc.o
[ +168 ms] [4/5] Linking CXX executable intermediates_do_not_run/bug
[        ] /snap/flutter/current/usr/bin/ld: warning: /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/crt1.o: unsupported GNU_PROPERTY_TYPE (5) type: 0xc0008002
[   +1 ms] [4/5] Install the project...
[  +12 ms] -- Install configuration: "Profile"
[   +4 ms] -- Installing: /home/fusion44/dev/stuff/bug/build/linux/x64/profile/bundle/bug
[        ] -- Set runtime path of "/home/fusion44/dev/stuff/bug/build/linux/x64/profile/bundle/bug" to "$ORIGIN/lib"
[        ] -- Installing: /home/fusion44/dev/stuff/bug/build/linux/x64/profile/bundle/data/icudtl.dat
[        ] -- Installing: /home/fusion44/dev/stuff/bug/build/linux/x64/profile/bundle/lib/libflutter_linux_gtk.so
[  +18 ms] -- Installing: /home/fusion44/dev/stuff/bug/build/linux/x64/profile/bundle/data/flutter_assets
[        ] -- Installing: /home/fusion44/dev/stuff/bug/build/linux/x64/profile/bundle/data/flutter_assets/version.json
[        ] -- Installing: /home/fusion44/dev/stuff/bug/build/linux/x64/profile/bundle/data/flutter_assets/packages
[        ] -- Installing: /home/fusion44/dev/stuff/bug/build/linux/x64/profile/bundle/data/flutter_assets/packages/cupertino_icons
[        ] -- Installing: /home/fusion44/dev/stuff/bug/build/linux/x64/profile/bundle/data/flutter_assets/packages/cupertino_icons/assets
[        ] -- Installing: /home/fusion44/dev/stuff/bug/build/linux/x64/profile/bundle/data/flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf
[        ] -- Installing: /home/fusion44/dev/stuff/bug/build/linux/x64/profile/bundle/data/flutter_assets/FontManifest.json
[        ] -- Installing: /home/fusion44/dev/stuff/bug/build/linux/x64/profile/bundle/data/flutter_assets/NOTICES.Z
[        ] -- Installing: /home/fusion44/dev/stuff/bug/build/linux/x64/profile/bundle/data/flutter_assets/fonts
[        ] -- Installing: /home/fusion44/dev/stuff/bug/build/linux/x64/profile/bundle/data/flutter_assets/fonts/MaterialIcons-Regular.otf
[   +1 ms] -- Installing: /home/fusion44/dev/stuff/bug/build/linux/x64/profile/bundle/data/flutter_assets/AssetManifest.json
[        ] -- Installing: /home/fusion44/dev/stuff/bug/build/linux/x64/profile/bundle/lib/libapp.so
[  +20 ms] Building Linux application... (completed in 2.725ms)
[ +152 ms] Observatory URL on device: http://127.0.0.1:34923/ZLyJK_2OVGY=/
[  +15 ms] Connecting to service protocol: http://127.0.0.1:34923/ZLyJK_2OVGY=/
[ +138 ms] Launching a Dart Developer Service (DDS) instance at http://127.0.0.1:0, connecting to VM service at http://127.0.0.1:34923/ZLyJK_2OVGY=/.
[ +107 ms] DDS is listening at http://127.0.0.1:42571/wEavpuc77xs=/.
[  +66 ms] Successfully connected to service protocol: http://127.0.0.1:34923/ZLyJK_2OVGY=/
[   +9 ms] Application running.
[  +32 ms] Connected to Linux
[   +2 ms] Flutter run key commands.
[   +2 ms] h List all available interactive commands.
[   +2 ms] c Clear the screen
[        ] q Quit (terminate the application on the device).
[   +3 ms] An Observatory debugger and profiler on Linux is available at: http://127.0.0.1:42571/wEavpuc77xs=/
[ +167 ms] The Flutter DevTools debugger and profiler on Linux is available at: http://127.0.0.1:9100?uri=http://127.0.0.1:42571/wEavpuc77xs=/

fusion44@fusion44-UM700:~/dev/stuff/bug$ flutter doctor -v
[✓] Flutter (Channel stable, 2.10.4, on Ubuntu 21.10 5.13.0-39-generic, locale de_DE.UTF-8)
    • Flutter version 2.10.4 at /home/fusion44/snap/flutter/common/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision c860cba910 (vor 2 Wochen), 2022-03-25 00:23:12 -0500
    • Engine revision 57d3bac3dd
    • Dart version 2.16.2
    • DevTools version 2.9.2

[!] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
    • Android SDK at /home/fusion44/Android/Sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/linux#android-setup for more details.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
    • cmake version 3.10.2
    • ninja version 1.8.2
    • pkg-config version 0.29.1

[✓] Android Studio (version 2021.1)
    • Android Studio at /snap/android-studio/119/android-studio
    • 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.11+0-b60-7590822)

[✓] VS Code
    • VS Code at /snap/code/current
    • Flutter extension version 3.38.1

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Ubuntu 21.10 5.13.0-39-generic
    • Chrome (web)    • chrome • web-javascript • Google Chrome 100.0.4896.75

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

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: animationAnimation APIsa: desktopRunning on desktopc: performanceRelates to speed or footprint issues (see "perf:" labels)engineflutter/engine related. See also e: labels.found in release: 2.10Found to occur in 2.10found in release: 2.13Found to occur in 2.13has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-linuxBuilding on or for Linux specificallyteam-linuxOwned by the Linux platform teamtriaged-linuxTriaged by the Linux platform team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions