Severe scrolling issues with UICollectionView

When there is a large number of supplementary views, scrolling is extremely slow.

To reproduce:

  1. Download Apple's demo of "Implementing Modern Collection Views" from here
  2. Open project in Xcode and show PinnedSectionHeaderFooterViewController.swift
  3. Go to line 106 and replace it with let sections = Array(0..<3000)
  4. Run project, navigate to "Pinned Section Headers" page, and try scrolling.

Scrolling is barely possible and extremely slow!

While profiling with Time instrument, issue seems to rely in invalidating supplementary views. Screenshot attached below.

How can I fix this? (I have many section headers in my view)