alexmercerind / flutter_acrylic

Flutter library for window acrylic, mica & transparency effects.
MIT License
605 stars 54 forks source link

Continuous Frame creation #29

Closed devmil closed 2 years ago

devmil commented 2 years ago

Hi, When using flutter_acrylic I see a continuous frame creation and a CPU load of ~10% even if no rebuild happens. The moment I remove flutter_acrylic the issue is gone.

I can also reproduce this with the example app from this repository.

Is this intended / needed / known?

CleanShot 2022-05-18 at 23 30 02

flutter doctor -v                                        
[✓] Flutter (Channel stable, 3.0.0, on macOS 12.3.1 21E258 darwin-arm, locale en-DE)
    • Flutter version 3.0.0 at /Users/mlamers/fvm/versions/stable
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ee4e09cce0 (9 days ago), 2022-05-09 16:45:18 -0700
    • Engine revision d1b9a6938a
    • Dart version 2.17.0
    • DevTools version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/mlamers/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • 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.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.3

[✓] 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 Ultimate Edition (version 2021.3.2)
    • IntelliJ at /Users/mlamers/Applications/JetBrains Toolbox/IntelliJ IDEA Ultimate.app
    • 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

[✓] IntelliJ IDEA Ultimate Edition (version 2021.3.2)
    • IntelliJ at /Users/mlamers/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/213.6777.52/IntelliJ IDEA.app
    • 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

[✓] IntelliJ IDEA Ultimate Edition (version 2021.3.1)
    • IntelliJ at /Users/mlamers/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/213.6461.79/IntelliJ IDEA.app
    • 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

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

[✓] Connected device (1 available)
    • macOS (desktop) • macos • darwin-arm64 • macOS 12.3.1 21E258 darwin-arm

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

• No issues found!

PS I had to do flutter pub upgrade in order to get rid of some problems in the win32 package in combination with Flutter 3

alexmercerind commented 2 years ago

Mind telling your Windows version?

devmil commented 2 years ago

Mind telling your Windows version?

It is macOS 12.3.1 running on an M1 Pro (14 inch). It doesn't matter if I run the arm or x86 variant. The win32 package is only complaining during compilation.

Adrian-Samoticha commented 2 years ago

Hello,

I am the maintainer of the macOS port of this library. No, this behavior is neither intended nor known.

I'll look into this issue and see whether I can reproduce it myself.

Adrian-Samoticha commented 2 years ago

Alright. First of all, trying to run the example project in Flutter 3 produces the following error on my end:

Error: 'Size' is imported from both 'dart:ffi' and 'dart:ui'.

This error can be fixed by upgrading bitsdojo_window from ^0.1.1+1 to ^0.1.2, a version that, as of writing, came out 11 hours ago. Did you perform this upgrade yourself, or did it somehow compile fine on your end without this change?

That said, I was able to reproduce the issue. The performance profiler looks even worse on my end than on yours and the app hovers at around 15 - 20 % CPU usage on my M1 MacBook Air:

image

Unfortunately, I am currently unsure how to fix this issue. I am relying on high-level Swift functions to achieve the transparency effect, which makes it difficult to assess the performance impact of the library.

devmil commented 2 years ago

Sorry, I missed to mention that I'm using a locally patched version of bitsdojo_window. That's really sad. Any idea what might trigger Flutter to do this?

Adrian-Samoticha commented 2 years ago

Not at the moment, though I did notice that this behavior doesn't change when the transparency effect is inactive (neither when the window is unfocused, nor when the effect is disabled entirely). Perhaps this has something to do with the view controller that is initialized in the MainFlutterWindow.swift file, then?

I'll have to look deeper into this.

devmil commented 2 years ago

I tried some things and it seems that as soon as I remove the TitlebarSafeArea Widget the problem seems to diappear. I will dig deeper...

devmil commented 2 years ago

fixed now on master