-
Notifications
You must be signed in to change notification settings - Fork 11
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
WIP - Scroll performance fixes for when there are many read posts already #66
base: main
Are you sure you want to change the base?
Conversation
@@ -61,9 +63,7 @@ struct SubredditFeedView: View { | |||
ThemedList(appTheme: appTheme, textSizePreference: textSizePreference, stripStyling: true) { | |||
if !posts.isEmpty && searchTerm.isEmpty { | |||
ForEach(posts, id: \.id) { post in | |||
var isRead: Bool { | |||
readPosts.contains(where: { $0.readPostId == post.id }) |
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.
This seemed to be the bottleneck.
|
||
var newReadIds: Set<String> = [] | ||
newPosts.forEach { post in | ||
let isRead = readPosts.contains(where: { $0.readPostId == post.id }) |
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.
We do the "slow" check on load, off the main thread.
Evaluating some alternatives to this that don't require a separate data structure. |
Evaluating some alternatives to this that don't require a separate data structure.
Description:
After adding the "mark read on scroll" feature, it seemed like scrolling performance took a hit. With some of my limited Instruments experience, it seemed like this was related to looking through the read posts FetchedResults to determine isRead when it gets to be several hundred items large. If I made the incorrect determination, then this PR is likely focused on a poor fix.
Altertnatives looked into: Adding an index. This didn't seem to help.
Changes:
Moved lookup to work off the main thread. This is at the expense of a slightly longer initial load for each page of content.
Removed an unused private function.
Keep track of read posts in memory for the current list.