-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 Traffic: Optimize table view updates by integrating diffable data source #22542
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
|
📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
|
… place The diffable data source relies on both the identity and the equality of the items it manages. The identity is determined by the item's hash, and equality is determined by whether the item's content has changed. If the content of an item is considered to have changed (even if its hash hasn't), the diffable data source may decide to reload that item
Use default hash(into...) implementation that calculates identity based on StatSection and RowType
Build StatsTrafficSnapshot instead of ImmuTable to be used in VC without changing any logic
- Create StatsTrafficDataSource - Apply snapshot instead of reloading table view
staskus
force-pushed
the
task/stats-traffic-diffable-optimization
branch
from
February 12, 2024 13:44
cd0ed06
to
5949c5e
Compare
staskus
changed the title
[WIP] Stats Traffic: Optimize table view updates by integrating diffable data source
Stats Traffic: Optimize table view updates by integrating diffable data source
Feb 12, 2024
staskus
added
[Type] Enhancement
and removed
[Status] Not Ready for Review
Part of a WIP Feature
labels
Feb 12, 2024
14 tasks
Make DiffableDataSource easier to integrate for existing ImmuTableVieHandler users Define common Snapshot and DataSource. Override delegate methods that rely on fetching row items.
staskus
force-pushed
the
task/stats-traffic-diffable-optimization
branch
from
February 13, 2024 08:52
5949c5e
to
0b8d77a
Compare
Generated by 🚫 Danger |
staskus
force-pushed
the
task/stats-traffic-diffable-optimization
branch
from
February 21, 2024 13:25
56e854f
to
d5aae87
Compare
Made the last little improvements, since I noticed a couple of issues after merging with the trunk:
|
guarani
approved these changes
Feb 22, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @staskus! The improvement in loading is noticeable! I couldn't spot any issues and don't have any feedback on the code.
This was referenced Feb 28, 2024
14 tasks
14 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Each time we update Stats data, we build a new
tableViewModel()
and reload all table view cells. It happens for each type of update we receive, which results in almost a dozen refreshes of table view cells happening in a short time. It can cause flickering of cell UI, or contribute to lag when scrolling.Solution
Implemented native
UITableViewDiffableDataSource
for Traffic tab which would only update table view cells if data changes. In a gist, we only need to make cell modelsHashable
, and the system will take care of efficient updates:Snapshot
andDataSource
types which depend onStatsTrafficSection
andStatsHashableImmuTableRow
to integrate within existingImmuTable
PeriodType
, soStatsTrafficSection
only depends on itImmuTableRow
for cells, soStatsHashableImmuTableRow
only depends on aHashable
version ofImmuTableRow
StatSection
and onRowType
. For example,periodAuthors
section andStatsGhostTwoColumnImmutableRow
row type.Hashable
Snapshot
the same way we previously builtImmuTable
view model. No changes in logic are necessary and we can follow a similar patternSiteStatsPeriodTableViewController
andImmuTable
to use a newDiffableDataSource
andapplySnapshot
instead of callingtableView.reloadData
Now any cell is only reloaded when the data of this particular cell changes.
If these changes prove successful, I plan to apply the same changes to the Insights tab to avoid similar issues such as flickering their as well.
Video
Before
before.MP4
After (together with #22592)
after.MP4
Regression Notes
Days/Weeks/Months/Years tabs remain unaffected since they use
SiteStatsPeriodTableViewControllerDeprecated
.The only unintended effect is implementing
Hashable
incorrectly. We want to make sure we identify each different period row uniquely but also detect when its content changes.Manual testing
PR submission checklist:
RELEASE-NOTES.txt
if necessary.UI Changes testing checklist: