-
Notifications
You must be signed in to change notification settings - Fork 193
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve channel list performance by enabling reconfigure cells #3186
Conversation
public func reloadChannels() { | ||
if isApplyingChangesets { | ||
DispatchQueue.main.async { | ||
self.reloadChannels() | ||
} | ||
return | ||
} | ||
|
||
isApplyingChangesets = true | ||
let previousChannels = channels | ||
let newChannels = Array(controller.channels) | ||
let stagedChangeset = StagedChangeset(source: previousChannels, target: newChannels) | ||
collectionView.reload(using: stagedChangeset, reconfigure: { _ in false }) { [weak self] newChannels in | ||
collectionView.reload(using: stagedChangeset, reconfigure: { _ in true }) { [weak self] newChannels in | ||
self?.channels = newChannels | ||
} | ||
isApplyingChangesets = false | ||
} |
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.
The issue was when reload called reconfigure cell and that in turn triggered Core Data store change which led to calling reloadChannels again. Then Apple throws an assert.
Pretty hard to unit-test this case.
I am thinking about using a boolean here which just reschedules reload channels if re-entrancy is detected.
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.
Probably not worth to to test it 馃
StreamChat XCMetrics
|
self?.channels = newChannels | ||
} | ||
isApplyingChangesets = false |
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.
Shouldn't this be set inside the reload completion block? 馃
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.
I also think that
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 is actually not a completion but it is the setData
closure which is called as a first thing in performBatchUpdates
(too early). This can be called multiple times although for us it seems to be called once (haven't dived into when exactly multiple changesets are generated).
func reload<C>(
using stagedChangeset: StagedChangeset<C>,
reconfigure: ((IndexPath) -> Bool)? = nil,
interrupt: ((Changeset<C>) -> Bool)? = nil,
setData: (C) -> Void
) {
where setData
is called after each changeset
for changeset in stagedChangeset {
if let interrupt = interrupt, interrupt(changeset), let data = stagedChangeset.last?.data {
setData(data)
return reloadData()
}
performBatchUpdates({
setData(changeset.data)
if !changeset.sectionDeleted.isEmpty {
deleteSections(IndexSet(changeset.sectionDeleted))
}
// later we call reconfigureItems which can trigger re-entrancy
In summary, it is in a correct places. Note that performBatchUpdates
's updates closure is not escaping and is called synchronously. Therefore, resetting the boolean is indeed at a correct place.
Flow:
- Set boolean to true
- Call reload
- Loop changesets
- Call setData
- Call reconfigureItems <-- boolean must be set false after calling reconfigure
- exit the reload function
- Set the boolean to false
121512c
to
a74a7ed
Compare
a74a7ed
to
442afd4
Compare
Quality Gate passedIssues Measures |
馃敆 Issue Links
Resolves ios-issues-tracking/790
馃幆 Goal
Enable cell reconfiguring and guard against reentrancy which led to an assertion in Apple's code/
馃摑 Summary
馃И Manual Testing Notes
Exploratory testing:
Open channel list and trigger channel list changes (e.g. new messages arriving)
鈽戯笍 Contributor Checklist