2

My project is a commercial project I cannot post here, but the code procedure is:

  1. GetAll(LINQ)
  2. filtering(Linq)
  3. pass IEnumerable result to RecyclerView Adapter
  4. Adapter convert IEnumerable<> to List<>
  5. Adapter Inflate the ItemCards

Big performance impact on #4, it takes up to 3 seconds on about 3k items.

How can I reduce the performance impact?

I noticed if I just create a new List<>(3000), it also takes about 1.5 seconds.

Or should I just not use the List?

How is Adapter fetching data by [position] if we don't use List<>.

How to go to particular Item in IEnumerable

ElementAt() gives my app totally died when inflate. It seems to do ToList() at every Items.

Community
  • 1
  • 1
nyconing
  • 1,092
  • 1
  • 10
  • 33
  • 3
    That's because main work is happening in the Step 4, when the `IEnumerable` is materialized to a `List` in the memory, before that there's no processing, its lazy execution. My understanding is even though you have finally only 3 K records, but initially in `GetAll` you get lots of records, which kills the performance. – Mrinal Kamboj Nov 14 '16 at 04:19
  • GetAll and filtering is taken less than 0.1 seconds. I cant even get that data filtered by prediction if I Not get the All Data. And step 4 is taken less time as if filtered result are less items. – nyconing Nov 15 '16 at 09:31

1 Answers1

1

Im find out problems by myself:

3.pass IEnumerable result to RecyclerView Adapter

Dont pass Enumerable to Adapter, or, it will re-query at every item. Pass List instead.

nyconing
  • 1,092
  • 1
  • 10
  • 33