Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Some more observations that might be helpful:</p> <p>I am able to reproduce the problem, using flow layout with around 175 items visible at once: it scrolls smoothly in the simulator but lags like hell on iPhone 5. Made sure they are opaque etc.</p> <p><img src="https://i.stack.imgur.com/Sq3a9.png" alt="enter image description here"></p> <p>What ends up taking the most time seems to be work with a mutable NSDictionary inside <code>_updateVisibleCellsNow</code>. Both copying the dictionary, but also looking up items by key. The keys seems to be UICollectionViewItemKey and the <code>[UICollectionViewItemKey isEqual:]</code> method is the most time consuming method of all. UICollectionViewItemKey contains at least <code>type</code>, <code>identifier</code> and <code>indexPath</code> properties, and the contained property indexPath comparison <code>[NSIndexPath isEqual:]</code> takes the most time.</p> <p>From that I'm guessing that the hash function of UICollectionViewItemKey might be lacking since <code>isEqual:</code> is called so often during dictionary lookup. Many of the items might be ending up with the same hash (or in the same hash bucket, not sure how NSDictionary works).</p> <p>For some reason it is faster with all items in 1 section, compared to many sections with 7 items in each. Probably because it spends so much time in NSIndexPath isEqual and that is faster if the row diffs first, or perhaps that UICollectionViewItemKey gets a better hash.</p> <p>Honestly it feels really weird that UICollectionView does that heavy dictionary work every scroll frame, as mentioned before each frame update needs to be &lt;16ms to avoid lag. I wonder if that many dictionary lookups either is:</p> <ul> <li>Really necessary for general UICollectionView operation</li> <li>There to support some edge case rarely used and could be turned off for most layouts</li> <li>Some unoptimized internal code that hasn't been fixed yet</li> <li>Some mistake from our side</li> </ul> <p>Hopefully we will see some improvement this summer during WWDC, or if someone else here can figure out how to fix it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload