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

WIP - Scroll performance fixes for when there are many read posts already #66

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mikedg1
Copy link
Contributor

@mikedg1 mikedg1 commented Nov 18, 2024

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.

image

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.

@@ -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 })
Copy link
Contributor Author

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 })
Copy link
Contributor Author

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.

@mikedg1 mikedg1 changed the title WIP - Scroll performance fixes for when there are many read posts already Scroll performance fixes for when there are many read posts already Nov 19, 2024
@mikedg1
Copy link
Contributor Author

mikedg1 commented Nov 19, 2024

Evaluating some alternatives to this that don't require a separate data structure.

@mikedg1 mikedg1 changed the title Scroll performance fixes for when there are many read posts already WIP - Scroll performance fixes for when there are many read posts already Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant