You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix perf regression in DiffableSnapshot init (#138)
Reverts some changes from #136.
When attempting to run the latest `main` in our app, I noticed that a
large list would take several seconds to appear.
Instruments shows that `DiffableSnapshot.init(viewModel:)` is the
culprit:
<img width="1047" alt="Screenshot 2024-10-14 at 15 07 25"
src="https://github.com/user-attachments/assets/e729033c-cc63-467c-80be-2678985c3050">
It turns out that appending items one by one is much slower than
appending them all at once.
This reverts the change to this method introduced in #136.
I also added a simple performance regression test, which generates 10
sections of 10,000 items each and runs some trivial assertion.
On the current `main`, this takes a very long time to complete. With the
reverted change on this branch it takes about ~200-300ms on my laptop.
(This still seems pretty slow to me, but I can't see any other obvious
ways of optimizing this.)
While running the test, I noticed some flaky failures, and the following
error being logged:
> Diffable data source detected an attempt to insert or append 1 item
identifier that already exists in the snapshot. The existing item
identifier will be moved into place instead, but this operation will be
more expensive. For best performance, inserted item identifiers should
always be unique. Set a symbolic breakpoint on
BUG_IN_CLIENT_OF_DIFFABLE_DATA_SOURCE__IDENTIFIER_ALREADY_EXISTS to
catch this in the debugger. Item identifier that already exists:
289A50E9
This is caused by the random ID generated for each cell by default – I
guess I got pretty (un)lucky here!
I feel that it makes more sense generally to just use the section/item
indexes as ids instead. I think this would also make it easier to debug
any off-by-one errors or similar issues in tests.
I have separated the fix and test changes into separate commits so you
can have a look yourself. (Or if you don't like the changes to the test,
it would make sense to just merge the fix itself.)
Nice one!
---------
Co-authored-by: Jesse Squires <[email protected]>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ NEXT
12
12
13
13
- Allow setting a `UICollectionViewDelegateFlowLayout` object to receive flow layout events from the collection view. ([@jessesquires](https://github.com/jessesquires), [#134](https://github.com/jessesquires/ReactiveCollectionsKit/pull/134))
14
14
- Swift Concurrency improvements: `@MainActor` annotations have been removed from most top-level types and protocols, instead opting to apply `@MainActor` to individual members only where necessary. The goal is to impose fewer restrictions/burdens on clients. ([@jessesquires](https://github.com/jessesquires), [#135](https://github.com/jessesquires/ReactiveCollectionsKit/pull/135))
15
-
- Various performance improvements. ([@jessesquires](https://github.com/jessesquires), [#136](https://github.com/jessesquires/ReactiveCollectionsKit/pull/136))
15
+
- Various performance improvements. ([@jessesquires](https://github.com/jessesquires), [#136](https://github.com/jessesquires/ReactiveCollectionsKit/pull/136), [@lachenmayer](https://github.com/lachenmayer), [#138](https://github.com/jessesquires/ReactiveCollectionsKit/pull/138))
0 commit comments