From c22cb6c32576b1aa73a88626168938520a6eac35 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 22 Jul 2020 13:35:41 -0600 Subject: [PATCH] Short-circuit room list store dispatch handling if not ready We were taking 0.2ms to handle the registration of a timer per event during startup, even before the app is visible to the user. These timers would be short-circuited too, leading to a bunch of wasted time. 0.2ms isn't a lot of time, but multiplied by thousands of events at startup it's pretty significant. On my account this reduces the full page spinner time from ~50 seconds to just over 20 seconds. --- src/stores/room-list/RoomListStore.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/stores/room-list/RoomListStore.ts b/src/stores/room-list/RoomListStore.ts index 308296e8bb..1f6c14ba2f 100644 --- a/src/stores/room-list/RoomListStore.ts +++ b/src/stores/room-list/RoomListStore.ts @@ -168,6 +168,12 @@ export class RoomListStoreClass extends AsyncStoreWithClient { } protected async onAction(payload: ActionPayload) { + // If we're not remotely ready, don't even bother scheduling the dispatch handling. + // This is repeated in the handler just in case things change between a decision here and + // when the timer fires. + const logicallyReady = this.matrixClient && this.initialListsGenerated; + if (!logicallyReady) return; + // When we're running tests we can't reliably use setImmediate out of timing concerns. // As such, we use a more synchronous model. if (RoomListStoreClass.TEST_MODE) {