[CIS-1854] [Internal] Move Model mappings to Background#2237
Conversation
…always to DiffChatMessage
Since the this was actually not causing the messages to jump
Also adds a function to make the removePublicDeclarations.sh more readable
📏 Size AnalysisTotal install size 9.7 MB | This change: ⬆️ +32.6 kB (+0.336%)🗂 See size breakdown
🔎 See the full size analysis (741f7c0) merging into develop (f8eb1ca)
|
martinmitrevski
left a comment
There was a problem hiding this comment.
Code-wise looks really good. I did some testing and there are solid performance improvements in the message list in UIKit. In SwiftUI, there's still a noticeable glitch when loading new messages, but we can iterate on this in the future.
To merge this, we would need some tests, and let's see how we communicate this change. Will there be doc update, where customers can opt in?
Not as of now, the idea is to use it internally, make sure things get to a better stage, and then allow customers to use it. |
nuno-vieira
left a comment
There was a problem hiding this comment.
Overall LGTM, the only thing I think we could improve is the Wrapper, and use a protocol instead. Or still, use the Wrapper, but inside, we could just move the ifs statements, to only one if statement, when creating the observer.
|
SonarCloud Quality Gate failed. |









🔗 Issue Links
https://stream-io.atlassian.net/browse/CIS-1854
https://stream-io.atlassian.net/browse/CIS-2059
🎯 Goal
The goal of this PR is to investigate the viability of moving the mapping of DTOs to Model to a background thread, reducing the pressure we put in the view/main thread.
📝 Summary
This PR introduces a new ListDatabaseObserver, matching the same API for simplicity purposes. This new object, named BackgroundListDatabaseObserver does exactly the same as its predecessor, but in a background and asynchronous way, and only notifies about results when those are already mapped.
🛠 Implementation
As of now:
_isBackgroundMappingEnabled, unlessforceLazyis passedAll this implementation is guarded now behind
_isBackgroundMappingEnabled. When the flag is false, the same behaviour as before will be present.When using DemoApp-StreamDevelopers, it uses Background Mapping by default
Pitfalls:
Because now background mapping tries to map every single updated dto as new updates come in, we end up resolving the whole tree for each object, which results in way too many fetches. This has no direct impact on the main thread per se, but the overhead we add to Core Data can be significant in some cases.
Also, in some cases, there are cyclic relationships, leading to Stack Overflow. This is now prevented from passing
forceLazy: trueto some models. This preserves the laziness of those properties. This is a temporary solution to those problems, but it is not meant to be the final one☑️ Contributor Checklist
🎁 Meme