-
Notifications
You must be signed in to change notification settings - Fork 212
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
Improve performance of ChatChannel
database model conversions ~7 times
#3325
Conversation
Sources/StreamChat/Utils/Database/NSManagedObject+Extensions.swift
Outdated
Show resolved
Hide resolved
Sources/StreamChat/Utils/Database/NSManagedObject+Extensions.swift
Outdated
Show resolved
Hide resolved
ChatChannel
database model conversions more than two timesChatChannel
database model conversions ~3.5x
ChatChannel
database model conversions ~3.5xChatChannel
database model conversions ~4.5x
ChatChannel
database model conversions ~4.5xChatChannel
database model conversions ~4.4x
0531f55
to
180eaaa
Compare
…than two times by using model data directly and not making additional fetch requests
a1ae7ff
to
6601b38
Compare
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.
It is looking good, but just added a couple more suggestions 👍
Sources/StreamChat/Utils/Database/NSManagedObject+Extensions.swift
Outdated
Show resolved
Hide resolved
if let oldest = dto.oldestMessageAt?.bridgeDate { | ||
messages = messages.filter { $0.createdAt >= oldest } | ||
} | ||
if let truncated = dto.truncatedAt?.bridgeDate { | ||
messages = messages.filter { $0.createdAt >= truncated } | ||
} | ||
return messages |
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 have some tests for these, so I kept this part to match what tests are expecting. Ideally we should add latestMessages to the ChannelDTO but I would prefer to do so in a separate PR.
ChatChannel
database model conversions ~4.4xChatChannel
database model conversions ~7x
ChatChannel
database model conversions ~7xChatChannel
database model conversions ~7 times
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.
LGTM! ✅ 🚀 Really happy to see we are cleaning up these things 🚀
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.
Great work 👏
Quality Gate passedIssues Measures |
🔗 Issue Links
Related to PBE-5004
🎯 Goal
Improve performance of
ChatChannel
database model conversions by removing additional fetch requests📝 Summary
ChatChannel
🛠 Implementation
In #3299 we removed CoreDataLazy and this opened up an opportunity to optimise
asModel()
functions (these convert local database data to immutable models likeChatChannel
). This PR replaces additional DB calls with accessing the NSManagedObject's data directly.🎨 Showcase
Profiling steps: log out Chewbacca, log in with Chewbacca, wait until CPU usage settles. Observe the time spent in converting
ChannelDTO
toChatChannel
when the user is opening the channel list.Measured: iPhone 12 Pro Max
279 ms > 38 ms 7x improvement
🧪 Manual Testing Notes
Exploratory testing around variety of channel actions, e.g. send a message > does everything look allright.
☑️ Contributor Checklist