Ffimageloading: Very poor performance in ListView

Created on 8 Jan 2017  路  11Comments  路  Source: luberda-molinet/FFImageLoading

I have try the CachedImage Controll in a Xamarin Form project and unfortunately I have to say the listview scroll is quite junky. It is definitely due to the images. If I remove the images from the cells there is no performance problems when scrolling.
The problem can be noted very easy by using the sample projects and modifying it to load images from the internet. The performance is especially bad if the phone has a slow internet connection (i.e. GPRS).
The good news is that it can somehow be fixed. I made the some tests with a modified version of the ImageLoader from MonoDroidToolkit (https://github.com/jamesmontemagno/MonoDroidToolkit) and (after fixing some bugs) it performs quite well. I think the performance problems are due to the way the CachedImage download of the images. Maybe you could take a look in the source code of the ImageLoader from MonoDroidToolkit and see what they do differently.

I really like the FFImageLoading project but this performance issues are keeping me from using it for production. I would appreciate if you could try fixing the issue.

Most helpful comment

@daniel-luberda The documentation is outdated. There is no AutomaticDecompression on NSUrlSessionHandler anymore.

I guess this should do on both platforms:

            HttpClient httpClient = new HttpClient();
            httpClient.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));
            ImageService.Instance.Initialize(new Configuration
            {
                HttpClient = httpClient
            });

All 11 comments

It is true that FFImageLoading and MonoDroidToolkit differ regarding downloading.
MonoDroidToolkit uses Android APIs, see: https://github.com/jamesmontemagno/MonoDroidToolkit/blob/master/MonoDroidToolkit/com.refractored.monodroidtoolkit/ImageLoader/ImageLoader.cs

Whereas FFImageLoading relies on HttpClient, which by default uses .NET stack for the networking (opening sockets, ...). All this can easily be overriden by specifying which HttpClientHandler to use, to do this just provide a preconfigured HttpClient to ImageService.Initialize().

This was done on purpose so people can really choose what they want to use.
I would recommend that you try to use either: Xamarin.Android.Net.AndroidClientHandler or ModernHttpClient then let us know if this provides better performances in your case.

@TheAndroidMachine Also there's a new setting in project build options, which allow to set this application-wide. See:

screen shot 2017-01-08 at 20 06 55

@TheAndroidMachine Did you try 2.2.7? It should have a better performance due to some new optimizations.

I tried the version 2.2.6 on Android with the Xamarin.Android.Net.AndroidClientHandler and indeed it is much faster now. The listview scrolls quite smooth. I also tried it with ModernHttpClient but the app crashes from time to time. So AndroidClientHandler is the winner. Maybe this solution should me mentioned in the wiki.

I just tried the 2.2.7 version but since the listview was already scrolling very well, it is hard to tell if the new version make it better. I will have to try it on a less powerful device. I will report the results asap.
I think the issue can be closed. Thanks.

@TheAndroidMachine Thanks for your feedback! :+1:
It would be great if you could update the Wiki with your observations/remarks, it's open for everyone.

@daniel-luberda @TheAndroidMachine
Setting for Android with the Xamarin.Android.Net.AndroidClientHandler, it seem only support for Android version 5.0 (or above).
Please tell me how to setting to both cases: Android version is lower 5.0 and Android version 5.0(or above) ?

@molinch how to configure httpclient to get better performance ?

@daniel-luberda The documentation is outdated. There is no AutomaticDecompression on NSUrlSessionHandler anymore.

I guess this should do on both platforms:

            HttpClient httpClient = new HttpClient();
            httpClient.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));
            ImageService.Instance.Initialize(new Configuration
            {
                HttpClient = httpClient
            });

Have you guys tried modernhttpclient-updated?

@daniel-luberda The documentation is outdated. There is no AutomaticDecompression on NSUrlSessionHandler anymore.

I guess this should do on both platforms:

Hi @daniel-luberda ! Is it possible to update the docs as 'AutomaticDecompression' doesn't exist in NSUrlSessionHandler now ?

Was this page helpful?
0 / 5 - 0 ratings