Asked by:
1.3.1, ListView and ImageCell performance on Android

Question
-
User98240 posted
Hey,
we are having major issues with ListView containing an ImageCell when deployed on a real device. It seems the image is not reused (or cached), so its always rendered a new when being shown on the view port. This results in poor scrolling performance.
Based on syntaxismyui examaple enclosed is a simple demo code for testing. Create a new PCL Solution named "Presidents" and copy paste the code into the presidents.cs, deploy on device and feel the lag!
Is there something we can do to improve performance?
using System; using Xamarin.Forms; using System.Collections.Generic; namespace Presidents { public class App : Application { public App() { // Some presidential data. http://www.americanpresidents.org/gallery/ List<President> presidents = new List<President> { new President ("George Washington", 1, "http://www.americanpresidents.org/images/01_150.gif"), new President ("John Adams", 2, "http://www.americanpresidents.org/images/02_150.gif"), new President ("Thomas Jefferson", 3, "http://www.americanpresidents.org/images/03_150.gif"), new President ("James Madison", 4, "http://www.americanpresidents.org/images/04_150.gif"), new President ("James Monroe", 5, "http://www.americanpresidents.org/images/05_150.gif"), new President ("John Quincy Adams", 6, "http://www.americanpresidents.org/images/06_150.gif"), new President ("Andrew Jackson", 7, "http://www.americanpresidents.org/images/07_150.gif"), new President ("Martin Van Buren", 8, "http://www.americanpresidents.org/images/08_150.gif"), new President ("William Henry Harrison", 9, "http://www.americanpresidents.org/images/09_150.gif"), new President ("John Tyler", 10, "http://www.americanpresidents.org/images/10_150.gif"), new President ("James K. Polk", 11, "http://www.americanpresidents.org/images/11_150.gif"), new President ("Zachary Taylor", 12, "http://www.americanpresidents.org/images/12_150.gif"), new President ("Millard Fillmore", 13, "http://www.americanpresidents.org/images/13_150.gif"), new President ("Franklin Pierce", 14, "http://www.americanpresidents.org/images/14_150.gif"), new President ("James Buchanan", 15, "http://www.americanpresidents.org/images/15_150.gif"), new President ("George Washington", 1, "http://www.americanpresidents.org/images/01_150.gif"), new President ("John Adams", 2, "http://www.americanpresidents.org/images/02_150.gif"), new President ("Thomas Jefferson", 3, "http://www.americanpresidents.org/images/03_150.gif"), new President ("James Madison", 4, "http://www.americanpresidents.org/images/04_150.gif"), new President ("James Monroe", 5, "http://www.americanpresidents.org/images/05_150.gif"), new President ("John Quincy Adams", 6, "http://www.americanpresidents.org/images/06_150.gif"), new President ("Andrew Jackson", 7, "http://www.americanpresidents.org/images/07_150.gif"), new President ("Martin Van Buren", 8, "http://www.americanpresidents.org/images/08_150.gif"), new President ("William Henry Harrison", 9, "http://www.americanpresidents.org/images/09_150.gif"), new President ("John Tyler", 10, "http://www.americanpresidents.org/images/10_150.gif"), new President ("James K. Polk", 11, "http://www.americanpresidents.org/images/11_150.gif"), new President ("Zachary Taylor", 12, "http://www.americanpresidents.org/images/12_150.gif"), new President ("Millard Fillmore", 13, "http://www.americanpresidents.org/images/13_150.gif"), new President ("Franklin Pierce", 14, "http://www.americanpresidents.org/images/14_150.gif"), new President ("James Buchanan", 15, "http://www.americanpresidents.org/images/15_150.gif"), new President ("George Washington", 1, "http://www.americanpresidents.org/images/01_150.gif"), new President ("John Adams", 2, "http://www.americanpresidents.org/images/02_150.gif"), new President ("Thomas Jefferson", 3, "http://www.americanpresidents.org/images/03_150.gif"), new President ("James Madison", 4, "http://www.americanpresidents.org/images/04_150.gif"), new President ("James Monroe", 5, "http://www.americanpresidents.org/images/05_150.gif"), new President ("John Quincy Adams", 6, "http://www.americanpresidents.org/images/06_150.gif"), new President ("Andrew Jackson", 7, "http://www.americanpresidents.org/images/07_150.gif"), new President ("Martin Van Buren", 8, "http://www.americanpresidents.org/images/08_150.gif"), new President ("William Henry Harrison", 9, "http://www.americanpresidents.org/images/09_150.gif"), new President ("John Tyler", 10, "http://www.americanpresidents.org/images/10_150.gif"), new President ("James K. Polk", 11, "http://www.americanpresidents.org/images/11_150.gif"), new President ("Zachary Taylor", 12, "http://www.americanpresidents.org/images/12_150.gif"), new President ("Millard Fillmore", 13, "http://www.americanpresidents.org/images/13_150.gif"), new President ("Franklin Pierce", 14, "http://www.americanpresidents.org/images/14_150.gif"), new President ("James Buchanan", 15, "http://www.americanpresidents.org/images/15_150.gif"), new President ("George Washington", 1, "http://www.americanpresidents.org/images/01_150.gif"), new President ("John Adams", 2, "http://www.americanpresidents.org/images/02_150.gif"), new President ("Thomas Jefferson", 3, "http://www.americanpresidents.org/images/03_150.gif"), new President ("James Madison", 4, "http://www.americanpresidents.org/images/04_150.gif"), new President ("James Monroe", 5, "http://www.americanpresidents.org/images/05_150.gif"), new President ("John Quincy Adams", 6, "http://www.americanpresidents.org/images/06_150.gif"), new President ("Andrew Jackson", 7, "http://www.americanpresidents.org/images/07_150.gif"), new President ("Martin Van Buren", 8, "http://www.americanpresidents.org/images/08_150.gif"), new President ("William Henry Harrison", 9, "http://www.americanpresidents.org/images/09_150.gif"), new President ("John Tyler", 10, "http://www.americanpresidents.org/images/10_150.gif"), new President ("James K. Polk", 11, "http://www.americanpresidents.org/images/11_150.gif"), new President ("Zachary Taylor", 12, "http://www.americanpresidents.org/images/12_150.gif"), new President ("Millard Fillmore", 13, "http://www.americanpresidents.org/images/13_150.gif"), new President ("Franklin Pierce", 14, "http://www.americanpresidents.org/images/14_150.gif"), new President ("James Buchanan", 15, "http://www.americanpresidents.org/images/15_150.gif"), new President ("George Washington", 1, "http://www.americanpresidents.org/images/01_150.gif"), new President ("John Adams", 2, "http://www.americanpresidents.org/images/02_150.gif"), new President ("Thomas Jefferson", 3, "http://www.americanpresidents.org/images/03_150.gif"), new President ("James Madison", 4, "http://www.americanpresidents.org/images/04_150.gif"), new President ("James Monroe", 5, "http://www.americanpresidents.org/images/05_150.gif"), new President ("John Quincy Adams", 6, "http://www.americanpresidents.org/images/06_150.gif"), new President ("Andrew Jackson", 7, "http://www.americanpresidents.org/images/07_150.gif"), new President ("Martin Van Buren", 8, "http://www.americanpresidents.org/images/08_150.gif"), new President ("William Henry Harrison", 9, "http://www.americanpresidents.org/images/09_150.gif"), new President ("John Tyler", 10, "http://www.americanpresidents.org/images/10_150.gif"), new President ("James K. Polk", 11, "http://www.americanpresidents.org/images/11_150.gif"), new President ("Zachary Taylor", 12, "http://www.americanpresidents.org/images/12_150.gif"), new President ("Millard Fillmore", 13, "http://www.americanpresidents.org/images/13_150.gif"), new President ("Franklin Pierce", 14, "http://www.americanpresidents.org/images/14_150.gif"), new President ("James Buchanan", 15, "http://www.americanpresidents.org/images/15_150.gif"), }; Label header = new Label { Text = "Presidents", Font = Font.SystemFontOfSize (35), HorizontalOptions = LayoutOptions.Center }; // Create a data template from the type ImageCell var cell = new DataTemplate (typeof(ImageCell)); cell.SetBinding (TextCell.TextProperty, "Name"); cell.SetBinding (TextCell.DetailProperty, new Binding ("Position", stringFormat: "{0}")); cell.SetBinding (ImageCell.ImageSourceProperty, "Image"); ListView listView = new ListView { ItemsSource = presidents, ItemTemplate = cell // Set the ImageCell to the item template for the listview }; // The root page of your application MainPage = new ContentPage { Padding = new Thickness (10, Device.OnPlatform (20, 0, 0), 10, 5), Content = new StackLayout { Children = { header, listView } } }; } protected override void OnStart() { // Handle when your app starts } protected override void OnSleep() { // Handle when your app sleeps } protected override void OnResume() { // Handle when your app resumes } } public class President { public President (string name, int position, string image) { this.Name = name; this.Position = position; this.Image = image; } public string Name { private set; get; } public int Position { private set; get; } public string Image { private set; get; } } }
Wednesday, January 14, 2015 2:51 PM
All replies
-
User98240 posted
It seems this is a bigger problem, crawling the forums i already found following references:
- https://forums.xamarin.com/discussion/24387/listview-scrolling-performance-xamarin-forms-vs-xamarin-android-or-xamarin-ios
- https://forums.xamarin.com/discussion/26187/listview-vs-android-unable-to-deploy-due-the-poor-performance
https://forums.xamarin.com/discussion/21738/listview-with-images-crashes-when-fast-scrolling
https://bugzilla.xamarin.com/show_bug.cgi?id=22510
- https://bugzilla.xamarin.com/show_bug.cgi?id=21890
Unfortunately i am still hunting for a solution.
Wednesday, January 14, 2015 3:34 PM -
User98240 posted
Another one regarding ListView performance:
- http://forums.xamarin.com/discussion/17303/listview-performance
I find it hard to imagine that such a simple example brings xamarin to its knees :(
Seems a solution is to use a custom renderer. Will investigate further.
Wednesday, January 14, 2015 4:00 PM -
User98240 posted
Ok its getting more weird. Tested the Code on a Samsung Galaxy S3 with Android 4.3 Jellybean and the ListView is smooth as ever. When testing on a Nexus S5 with Android 5.0 Lollipop the ListView lags. Also the debug console shows a lot of Garbage collection activity when scrolling. The Galaxy S3 debug output had almost Zero GC messages.
[Mono] GC_BRIDGE waiting for bridge processing to finish [art] Explicit concurrent mark sweep GC freed 2191(54KB) AllocSpace objects, 4(64KB) LOS objects, 40% free, 15MB/26MB, paused 1.026ms total 10.774ms [Mono] GC_OLD_BRIDGE num-objects 76 num_hash_entries 89 sccs size 89 init 0.00ms df1 0.39ms sort 0.05ms dfs2 0.40ms setup-cb 0.03ms free-data 0.09ms links 13/13/13/1 dfs passes 178/102 [Mono] GC_MAJOR: (LOS overflow) pause 7.08ms, total 7.30ms, bridge 12.62ms major 1152K/1104K los 319K/16620K [art] Explicit concurrent mark sweep GC freed 2143(51KB) AllocSpace objects, 4(74KB) LOS objects, 40% free, 15MB/26MB, paused 375us total 10.019ms [Mono] GC_OLD_BRIDGE num-objects 74 num_hash_entries 86 sccs size 86 init 0.00ms df1 0.42ms sort 0.05ms dfs2 0.39ms setup-cb 0.03ms free-data 0.09ms links 12/12/12/1 dfs passes 172/98 [Mono] GC_MAJOR: (LOS overflow) pause 6.51ms, total 6.64ms, bridge 11.69ms major 1152K/1152K los 263K/16704K [Mono] GC_BRIDGE waiting for bridge processing to finish [art] Explicit concurrent mark sweep GC freed 2154(52KB) AllocSpace objects, 4(74KB) LOS objects, 40% free, 15MB/26MB, paused 294us total 10.449ms [Mono] GC_OLD_BRIDGE num-objects 75 num_hash_entries 88 sccs size 88 init 0.00ms df1 0.46ms sort 0.05ms dfs2 0.44ms setup-cb 0.04ms free-data 0.10ms links 13/13/13/1 dfs passes 176/101 [Mono] GC_MAJOR: (LOS overflow) pause 8.83ms, total 9.24ms, bridge 12.65ms major 1072K/1152K los 177K/16663K [Mono] GC_BRIDGE waiting for bridge processing to finish [art] Explicit concurrent mark sweep GC freed 2386(63KB) AllocSpace objects, 9(206KB) LOS objects, 40% free, 15MB/26MB, paused 478us total 13.390ms [Mono] GC_OLD_BRIDGE num-objects 79 num_hash_entries 88 sccs size 88 init 0.00ms df1 0.42ms sort 0.04ms dfs2 0.38ms setup-cb 0.03ms free-data 0.09ms links 9/9/9/1 dfs passes 176/97 [Mono] GC_MAJOR: (LOS overflow) pause 7.07ms, total 7.21ms, bridge 15.20ms major 1088K/1072K los 145K/16577K [Mono] GC_BRIDGE waiting for bridge processing to finish [art] Explicit concurrent mark sweep GC freed 2472(66KB) AllocSpace objects, 9(206KB) LOS objects, 40% free, 15MB/26MB, paused 464us total 12.137ms [Mono] GC_OLD_BRIDGE num-objects 82 num_hash_entries 95 sccs size 95 init 0.00ms df1 0.41ms sort 0.05ms dfs2 0.42ms setup-cb 0.04ms free-data 0.07ms links 13/13/13/1 dfs passes 190/108
Wednesday, January 14, 2015 4:26 PM -
User98240 posted
Can the problem be related to the ART-Runtime? It seems every Dalvik system performs fine.
Wednesday, January 14, 2015 5:53 PM -
User98240 posted
I created a github repository for easier testing and verification: https://github.com/rebuy-de/xamarin-listview
To verify check out the repository, download the packages and deploy on an android device. When comparing on emulated android 5.0.0 and 4.4.4 devices you see that the Images lag behind and the 4.4.4 ListView performance is much snappier.
Wednesday, January 14, 2015 10:30 PM -
User98240 posted
Just tested with a Nexus 4 running Android 4.4 KitKat. The ListView is lagy, so beginning with 4.4 there seems to be a problem, ill investigate further.
Thursday, January 15, 2015 9:00 AM -
User98240 posted
Okay, we probably found the cause of the problem. Its an issue with gifs! When using jpgs the ListView scrolls fine. To test use following branch, it includes jpges instead of gifs: https://github.com/rebuy-de/xamarin-listview/tree/jpg
Unfortunately there seems to be no workaround. So either convert your images or wait for a fix :\
Thursday, January 15, 2015 1:43 PM -
User98240 posted
Created a bug report, in case someone find from the feature reads this thread ;) https://bugzilla.xamarin.com/show_bug.cgi?id=26054
Its also already confirmed, so lets hope the best.
Thursday, January 15, 2015 1:51 PM -
User10864 posted
Hi @OtaMares , it may be related to this one: https://bugzilla.xamarin.com/show_bug.cgi?id=23807 Also confirmed.
Tuesday, February 3, 2015 5:38 AM