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.
This commit is contained in:
Florian Duros 2026-02-27 14:40:30 +01:00
parent 135f5728db
commit b5c879ae85
No known key found for this signature in database
GPG Key ID: A5BBB4041B493F15

View File

@ -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,