Flutter_cached_network_image: Weird performance issue (CPU > 100%) until manual rebuild

Created on 9 Jul 2019  路  5Comments  路  Source: Baseflow/flutter_cached_network_image

Hi,
I have a strange performance issue on my app on both simulators (iOS and Android). I am displaying 6 times the same image from the network. Images are not big and they load quite fast.

The CPU usage of the app (Runner.app & qemu-system-i386) goes up and stay at at least 100% CPU and the usage stays like this forever.

My app has a refresh (reloads a JSON than trigger a rebuild of my list with the 6 items) and when I hit the refresh, the CPU goes back to normal (around 0.5-2%).

I tried a simple test by replacing the CachedNetworkImage with a simple Placeholder widget, I don't have this issue at all.
As soon as I replace it back with a CachedNetworkImage wdiget, I get the high CPU usage until I do a refresh, and then it all goes smoothly.

I am using cached_network: ^1.0.0 version with Flutter stable 1.7.8.

Any idea what could produce this ?

Most helpful comment

@renefloor I've tried with the master branch, and I confirm that this PR has fixed my issue! 馃憤
Any idea when you'll release a new version of the package?

All 5 comments

I am investigating this issue. Not sure where it is coming from.

Thanks!
Here is the code snippet I am using for displaying the image :

@override
  Widget build(BuildContext context) {
    return CachedNetworkImage(
            imageUrl: imageUrl,
            placeholder: (_, url) => Container(
                  width: width,
                  height: height,
                  child: Center(
                    child: CircularProgressIndicator(),
                  ),
                ),
            fit: BoxFit.cover,
            width: width,
            height: height,
            errorWidget: (_, url, error) => Container(),
          );
  }

Maybe a hint:
I've noticed that the CircularProgressIndicator widget is a very CPU intensive widget (especially in debug mode).
So if the placeholder widget is not disposed correctly when the image is loaded & displayed, that might explained the CPU hogs as I might have 6 progress indicators still animating somehow.
The rebuild probably don't use the placeholders since the images are restored from cache...

What do you think ?

That seems to be the problem indeed. Pull request #194 seems to fix this (among with the better animation), so it will probably be better in the next version.

@renefloor I've tried with the master branch, and I confirm that this PR has fixed my issue! 馃憤
Any idea when you'll release a new version of the package?

Yes, released it Saturday (1.1.0)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ened picture ened  路  4Comments

sososdk picture sososdk  路  5Comments

Gavin-1991 picture Gavin-1991  路  6Comments

creativecreatorormaybenot picture creativecreatorormaybenot  路  4Comments

gjrjf picture gjrjf  路  4Comments