Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ui): Fix performance of `AllRemoteEvents::(in|de)crement_all_time…
…line_item_index_after`. This patch fixes the performance of `AllRemoteEvents::increment_all_timeline_item_index_after` and `decrment_all_timeline_item_index_after`. It appears that the code was previously iterating over all items. This is a waste of time. This patch updates the code to iterate over all items in reverse order: - if `new_timeline_item_index` is 0, we need to shift all items anyways, so all items must be traversed, the iterator direction doesn't matter, - otherwise, it's unlikely we want to traverse all items: the item has been either inserted or pushed back, so there is no need to traverse the first items; we can also break the iteration as soon as all timeline item index after `new_timeline_item_index` has been updated. I'm testing this patch with the `test_lazy_back_pagination` test in #4594. With 10_000 events in the sync, the `ObservableItems::push_back` method (that uses `AllRemoteEvents::increment_all_timeline_item_index_after`) was taking 7% of the whole execution time. With this patch, it takes 0.7%.
- Loading branch information