Bloc: CPU usage spike after upgrading to 3.0.0

Created on 28 Dec 2019  ·  11Comments  ·  Source: felangel/bloc

Describe the bug
After upgrading flutter_bloc to 3.0.0 (and rxdart to 0.23.1) I've noticed slight spike in CPU usage by Android Emulator (qemu-system-x86_64.exe process, Windows 10). Immediately after starting the app CPU usage jumps to 40+% and just stays there even though app does nothing.
If downgraded back to 2.1.1 (rxdart to 0.22.0) and restarting the app it falls to 4-5% and everything is ok.

To Reproduce
Steps to reproduce the behavior:

  1. Upgrade flutter_bloc to 3.0.0 and rxdart to 0.23.1
  2. Start the app
  3. Check CPU usage in task manager

Expected behavior
CPU usage stays low.

Paste the output of running flutter doctor -v here.

[√] Flutter (Channel beta, v1.12.13+hotfix.6, on Microsoft Windows [Version 10.0.17763.914], locale en-US)
• Flutter version 1.12.13+hotfix.6 at C:\flutter
• Framework revision 18cd7a3601 (2 weeks ago), 2019-12-11 06:35:39 -0800
• Engine revision 2994f7e1e6
• Dart version 2.7.0

[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at C:\Usersamunk\AppData\Local\Android\sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
• All Android licenses accepted.

[√] Android Studio (version 3.5)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 42.1.1
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)

[√] VS Code (version 1.41.1)
• VS Code at C:\Usersamunk\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.7.1

[√] Connected device (1 available)
• AOSP on IA Emulator • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)

• No issues found!

bug dependency

Most helpful comment

Well, I did compare counter app with and without bloc... and both did not have any issues. And also I'm not able to reproduce it in my main app anymore, so guess it was somehow related to stars alignment, time of a day or just my computer was angry with me for some reason. Sorry for bothering you!

All 11 comments

Hi @liri2006 👋
Thanks for opening an issue!

This is more likely a Flutter issue than a bloc issue as bloc v3.0.0 requires Flutter >=v1.12.1. Are you able to compare a counter app with setState and a counter app with bloc to see if the CPU spike only occurs in the bloc variant? Thanks!

Well, I did compare counter app with and without bloc... and both did not have any issues. And also I'm not able to reproduce it in my main app anymore, so guess it was somehow related to stars alignment, time of a day or just my computer was angry with me for some reason. Sorry for bothering you!

Hi, noticed the same thing, actually I upgraded from 1.0.0 to 3.0.0 and encountered the issue. Pretty sure it does not come from Flutter and here is why : I checked my pubspec.lock _"without upgrade"_ vs _"with upgrade"_ of flutter_bloc and I have noticed that my SDK version was already 1.12.13+hotfix.4 in both cases, the only upgrades that happened were :

  • bloc 1.0.1 -> 3.0.0
  • rxDart 0.22.6 -> 0.23.1
  • provider 3.2.0 -> 4.0.0
  • a new dependency : nested 0.0.4

    I didn't have time to do further investigations. (Don't have my usb-c adapter with me to profile on device)

@tenninebt Can you try to downgrade to flutter_bloc 2.1.1 and rxdart 0.22.0? That's what helped me in the morning. Btw, I was initially updating from flutter_bloc 0.21.0.

I am skeptical that bloc is the issue because there were no major changes to bloc itself. Most of the big changes were in provider and rxdart. If you can provide detailed reproduction steps and have good reason to suspect bloc I'm happy to look into it but given the changes it wouldn't make sense to me.

@felangel I totally understand, that's why I said it is one of the upgrade that comes with bloc (could be rx or provider).
@liri2006 I did downgrade to 2.1.1 which solves the issues (same as downgrading to 1.0.0).
I'll have a look asap, probably next week and I'll post my findings.

Just had a look at provider repository, I think we have a winner : https://github.com/rrousselGit/provider/issues/308
The fix is live (4.0.1), it does fix the issue. I guess for the next release, the dependency should be to >=4.0.1.

The dependency should be fine then.

flutter_bloc uses provider: ^4.0.0, which is also suitable for 4.0.1. Just be sure to update your dependencies again to fetch those changes I guess. :-)

What I meant is as long as the version is not explicitly constrained, there a risk of other people facing the issue, (if they have an explicit 4.0.0 direct dependency I guess, but maybe in other cases too), forcing the dependency to be ^4.0.1 is safer as they either will have the right version or a conflict when getting the packages, it is clearly not urgent, but nice to have on a next version.

I'll include this in v3.1.0 👍

Published in flutter_bloc v3.1.0 🎉

Was this page helpful?
0 / 5 - 0 ratings