WordPress-iOS icon indicating copy to clipboard operation
WordPress-iOS copied to clipboard

Stats Period / Stats Traffic: Improve scrolling performance

Open staskus opened this issue 1 year ago • 4 comments

The Stats Traffic tab's scrolling performance still stutters, even on iPhone 14 Pro. There may be some inefficiencies in how cells are built:

  1. Timebox an improvement task (e.g. 1 day)
  2. Use Animation Hitches and/or TimeProfiler to identify the most inefficient reloads
  3. Try to make improvements to the most inefficient reloads

staskus avatar Feb 28 '24 15:02 staskus

Thanks for reporting! 👍

dangermattic avatar Feb 28 '24 15:02 dangermattic

Thanks! I also see the stuttering during pull-to-refresh on the Traffic tab or the Insights tab.

guarani avatar Feb 28 '24 21:02 guarani

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
image

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.

image

TopTotalsCell is highly configurable and used for fileDownloadsTableRows, videosTableRows, postsAndPagesTableRows, referrersTableRows, clicksTableRows, authorsTableRows, searchTermsTableRows.

TimeProfiler indicates issues with:

  • UITableViewCell addRows() extension calls
  • TopTotalsCell setSubtitleVisibility calls

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

image

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:

  • CountriesMapCell setting countriesMapView on a UIStackView which in turn loads a 3rd party FSInteractiveMapView
  • Similar issues to TopTotalsCell: CountriesCell making UITableViewCell addRows() extension calls, setSubtitleVisibility calls

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.

staskus avatar Mar 14 '24 16:03 staskus

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.

guarani avatar Mar 15 '24 00:03 guarani