Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stats: Improve scrolling performance #22847

Open
wants to merge 7 commits into
base: trunk
Choose a base branch
from

Conversation

staskus
Copy link
Contributor

@staskus staskus commented Mar 18, 2024

Fixes #22721

Majority of Stats Traffic / Stats Period scrolling hitches happen due to inefficient TopTotalsCell load, mainly calls to addRows which creates and adds multiple layers of UIStackViews every time the cell is configured.

Investigation: pc8eDl-1pe-p2

Solution

  • Create and add UIStackView only once when the table view loads. When other cells reuse the same views, only configure or hide existing views.
  • Use setNeedsLayout instead of layoutIfNeeded

This is only the first iteration of possible improvements. I didn't achieve a full smooth experience and animation hitches still happen after the first load. However, the improvements are measurable and visible, especially when testing on a debugger-connected iPhone.

Performance Comparisons

I decided to compare the performance of cell configuration methods by measuring how much time it takes to fully configure the cell. When testing, I use a high-traffic site and scroll up and down three times.

TopTotalsCell

iPhone 14 Pro

Condition Performance Average (s) Improvement Factor
Before 0.023552464503867953 -
After 0.005567020840115017 4.2x faster

CountriesCell

iPhone 14 Pro

Condition Performance Average (s) Improvement Factor
Before 0.02454930543899536 -
After 0.004590545381818499 5.3x faster

All Stats Cells Averages

The improvement of the configuration of all the Stats cell averages falls somewhere in between of two numbers.

iPhone 14 Pro

Condition Performance Average (s) Improvement Factor
Before 0.011049999985643613 -
After 0.0023589220599851747 4.68x faster

Hitches Comparisons

Before

Hitches Before - No Debugger

After

Hitches After - With Subtitle Visibility

Remaining Hitches

The majority of those remaining hitches are caused by issues that couldn't be identified or sometimes identified simply as main using Time Profiler:

image

To test:

  1. Build Jetpack app on trunk with a debugger connected
  2. Select higher-traffic site
  3. Open Stats, select Days/Weeks/Months/Years tab
  4. Scroll up and down a couple of times, and observe the performance
  5. Build Jetpack app on task/22721-stats-traffic-improve-scrolling-performance with a debugger connected
  6. Open Stats, select Days/Weeks/Months/Years tab
  7. Scroll up and down a couple of times, and observe the performance
  8. Confirm that cell appearance is not broken
  9. Disconnect the debugger
  10. Open Stats, select Days/Weeks/Months/Years tab
  11. Scroll up and down a couple of times, and observe the performance
  12. Confirm that cell appearance is not broken

Regression Notes

  1. Potential unintended areas of impact

TopTotalsCell is only used within Stats, doesn't affect any other areas

  1. What I did to test those areas of impact (or what existing automated tests I relied on)

Manual testing, and performance measurement

  1. What automated tests I added (or what prevented me from doing so)

None

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding unit tests for my changes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

Testing checklist:

  • WordPress.com sites and self-hosted Jetpack sites.
  • Portrait and landscape orientations.
  • Light and dark modes.
  • Fonts: Larger, smaller and bold text.
  • High contrast.
  • VoiceOver.
  • Languages with large words or with letters/accents not frequently used in English.
  • Right-to-left languages. (Even if translation isn’t complete, formatting should still respect the right-to-left layout)
  • iPhone and iPad.
  • Multi-tasking: Split view and Slide over. (iPad)

TopTotalsCell was calling addRows on every configuration of cell which in turn created and added a hierarchy of UIStackView-based views.

Optimizing TopTotalsCell to only add rows once and then make manipulations on existing rows.
@wpmobilebot
Copy link
Contributor

wpmobilebot commented Mar 18, 2024

WordPress Alpha📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
App NameWordPress Alpha WordPress Alpha
ConfigurationRelease-Alpha
Build Numberpr22847-2674401
Version24.6
Bundle IDorg.wordpress.alpha
Commit2674401
App Center BuildWPiOS - One-Offs #9460
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Mar 18, 2024

Jetpack Alpha📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
App NameJetpack Alpha Jetpack Alpha
ConfigurationRelease-Alpha
Build Numberpr22847-2674401
Version24.6
Bundle IDcom.jetpack.alpha
Commit2674401
App Center Buildjetpack-installable-builds #8503
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@staskus staskus changed the title Stats Traffic: Improve scrolling performance Stats Period: Improve scrolling performance Apr 10, 2024
@staskus staskus marked this pull request as ready for review April 10, 2024 08:48
@staskus staskus requested review from guarani and removed request for guarani April 10, 2024 08:49
@staskus staskus changed the title Stats Period: Improve scrolling performance Stats: Improve scrolling performance Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stats Period / Stats Traffic: Improve scrolling performance
2 participants