Stats Period / Stats Traffic: Improve scrolling performance
The Stats Traffic tab's scrolling performance still stutters, even on iPhone 14 Pro. There may be some inefficiencies in how cells are built:
- Timebox an improvement task (e.g. 1 day)
- Use Animation Hitches and/or TimeProfiler to identify the most inefficient reloads
- Try to make improvements to the most inefficient reloads
Thanks for reporting! 👍
Thanks! I also see the stuttering during pull-to-refresh on the Traffic tab or the Insights tab.
Analysis
Hitches can be identified using Animation Hitches Instrument.
Apple classifies Hitches as:
- Critical if the hitch lasts longer than 10ms per second
- Warning if the hitch lasts between 5 to 10ms per second
- Good if the hitch lasts less than 5 ms per second
I ran Hitches instrument on iPhone 14 Pro by loading Traffic tab on a high-traffic site and scrolling up and down a couple of times. I repeated the testing cycle a few times to see if the same issues were consistently reported.
TopTotalsCell
TopTotalsCell activity was seen most frequently before the hitch was reported.
TopTotalsCell is highly configurable and used for fileDownloadsTableRows, videosTableRows, postsAndPagesTableRows, referrersTableRows, clicksTableRows, authorsTableRows, searchTermsTableRows.
TimeProfiler indicates issues with:
UITableViewCell addRows()extension callsTopTotalsCell setSubtitleVisibilitycalls
At each configuration, cells add and remove nested UIStackViews and its rows. The hitch can be seen live when scrolling on the device. Right before a new cell appears, scrolling stutters for a second. If we remove this nested stack view configuration, the stutter disappears.
CountriesCell & CountriesMapCell
Before the Country row with a map appears, a small stutter can be experienced on the device which is also registered by Hitches instrument. Time Profiler indicates couple of issues:
CountriesMapCellsettingcountriesMapViewon aUIStackViewwhich in turn loads a 3rd partyFSInteractiveMapView- Similar issues to
TopTotalsCell:CountriesCellmakingUITableViewCell addRows()extension calls,setSubtitleVisibilitycalls
BottomScrollAnalytics
Minor Animation Hitches are also reported around the time calls to analytics are made. ImmuTableHandler observes scrollViewWillEndDragging to report trackScrollToBottomEvent. This particular event is not required for StatsTraffic feature and could be removed. Since it's reported when the bottom of the scroll view is reached, it's unlikely this call contributes to any visible stutter. It's worth re-running Hitches instrument after other more impactful issues are resolved to see if stutters are still visible and if Hitches are still reported around analytics calls.
Next Step
UIStackView usage needs to be optimized since it looks to be the main reason that causes stutters when scrolling Stats table view. It affects most of the available rows due to UITableViewCell addRows() calls being made. I already started doing some optimization work and hope to make improvements.
I'm just letting you know I'm reorganizing the "Performance improvements" issues and moved them to a new GitHub project. I will clarify this over Slack.