From b5c879ae853225c7d00407ea44e22780a862ac2e Mon Sep 17 00:00:00 2001 From: Florian Duros Date: Fri, 27 Feb 2026 14:40:30 +0100 Subject: [PATCH] perf(room list): avoid to create new filter ids and keys when the room list is updated The filterKeys are passed in the virtuoso context so it should reduce internal computing The filter ids array has always the same value, there is no point to create a new instance. --- .../src/viewmodels/room-list/RoomListViewViewModel.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/web/src/viewmodels/room-list/RoomListViewViewModel.ts b/apps/web/src/viewmodels/room-list/RoomListViewViewModel.ts index 093deba491..ed1c305796 100644 --- a/apps/web/src/viewmodels/room-list/RoomListViewViewModel.ts +++ b/apps/web/src/viewmodels/room-list/RoomListViewViewModel.ts @@ -25,6 +25,7 @@ import { RoomNotificationStateStore } from "../../stores/notifications/RoomNotif import { RoomListItemViewModel } from "./RoomListItemViewModel"; import { SdkContextClass } from "../../contexts/SDKContext"; import { hasCreateRoomRights } from "./utils"; +import { keepIfSame } from "../../utils/keepIfSame"; interface RoomListViewViewModelProps { client: MatrixClient; @@ -407,13 +408,16 @@ export class RoomListViewViewModel // Build the complete state atomically to ensure consistency // roomIds and roomListState must always be in sync const roomIds = this.roomIds; + + // Update filter keys - only update if they have actually changed to prevent unnecessary re-renders of the room list + const previousFilterKeys = this.snapshot.current.roomListState.filterKeys; + const newFilterKeys = this.roomsResult.filterKeys?.map((k) => String(k)); const roomListState: RoomListViewState = { activeRoomIndex, spaceId: this.roomsResult.spaceId, - filterKeys: this.roomsResult.filterKeys?.map((k) => String(k)), + filterKeys: keepIfSame(previousFilterKeys, newFilterKeys), }; - const filterIds = [...filterKeyToIdMap.values()]; const activeFilterId = this.activeFilter !== undefined ? filterKeyToIdMap.get(this.activeFilter) : undefined; const isRoomListEmpty = roomIds.length === 0; const isLoadingRooms = RoomListStoreV3.instance.isLoadingRooms; @@ -422,7 +426,6 @@ export class RoomListViewViewModel this.snapshot.merge({ isLoadingRooms, isRoomListEmpty, - filterIds, activeFilterId, roomListState, roomIds,