Skip to content

Commit

Permalink
[lib] Avoid creation new ChatThreadItem unnecessarily in getSearchRes…
Browse files Browse the repository at this point in the history
…ultsForEmptySearchText

Summary:
In the process of [investigating ENG-5674](https://linear.app/comm/issue/ENG-5674/improve-performance-of-useflattenedchatlistdata#comment-df182f4b), I noticed an issue here. I had implemented a caching layer for `useFlattenedChatListData` so that it would avoid creating a new `ChatThreadItem` when the underlying data for it had not changed in Redux. But the code here was recreating the `ChatThreadItem` on every render anyways, forcing a bunch of components to rerender (and values to be recalculated) unnecessarily.

While I don't have a good long-term solution for ENG-5674 (and I probably won't prioritize it anytime soon), I think it's always best to avoid constructing new objects when the existing object suffices.

Test Plan: Flow

Reviewers: tomek, angelika

Reviewed By: tomek

Differential Revision: https://phab.comm.dev/D13903
  • Loading branch information
Ashoat committed Nov 12, 2024
1 parent 69d28f2 commit 8a334ca
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/shared/thread-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1468,6 +1468,9 @@ function getSearchResultsForEmptySearchText(
threadIsInHome(sidebar.threadInfo) ===
threadIsInHome(item.threadInfo),
);
if (sidebarsOnlyInSameTab.length === item.sidebars.length) {
return item;
}
return {
...item,
sidebars: sidebarsOnlyInSameTab,
Expand Down

0 comments on commit 8a334ca

Please sign in to comment.