New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding large number of items slow #36
Comments
An |
Any ideas how to improve this? |
Accidentialy closed this |
Its probably because |
Yea, I tried it with the list version, same issue. I dug into it a little more, looking at traceview, it looks like all the time is spent in calls to notifyDataSetChanged. I see that you've set it to not notify on change in the addItems() method, but it looks like the DrawerItem.attachTo is explicitly calling notifyDataSetChanged for every item, so it ends up doing O(n^2) redraws of the list. Callling setNotifyOnChange(false) only prevents the implicit calls to notifyDataSetChanged from adding items to the adapter, it doesn't appear to prevent the explicit calls. Once all the extra calls to notifyDataSetChanged are eliminated however, it looks like another bug crops up related to the default DrawerItem id being set as the system current time. It appears that the items are added so fast to the adapter now that many end up with the same system time, and thus the adapter removes an "old" version and replaces it with the "new" one. For example, in the following test case List<DrawerItem> items = new ArrayList<>();
for(int i = 0; i < 100; i++) {
items.add(new DrawerItem()
.setTextPrimary("test"));
}
drawer.addItems(items); only 6 or 7 items end up in the drawer. I don't feel like I'm familiar enough with the code to send a pull request, but hopefully this helps in tracking down the issue. |
Thank you for this idea. I tested your approach with |
When I try to add a large number of items to the drawer (couple hundred for example, use case similar to gmail app having the list of labels in the drawer) it takes a long time (minutes) to finish drawing the drawer. The logcat shows D/DrawerView: updateList() over and over.
The text was updated successfully, but these errors were encountered: