Break up the event loop tasks for the room list
The room list does a hefty amount of work, so instead of blocking the event loop with a `/sync` request and a bunch of room updates (as we can get multiple per sync) we can instead run it over several smaller tasks. The smaller tasks help the event loop do other things between our tasks, ensuring we don't inadvertently block the UI from rendering too slowly. On my account and machine, this cuts the time to render in half (~30ms, down from ~60ms) .
This commit is contained in:
parent
1315f34662
commit
8624e8beeb
1 changed files with 7 additions and 1 deletions
|
@ -114,7 +114,13 @@ export class RoomListStore2 extends AsyncStore<ActionPayload> {
|
||||||
if (!quiet) this.updateFn.trigger();
|
if (!quiet) this.updateFn.trigger();
|
||||||
};
|
};
|
||||||
|
|
||||||
protected async onDispatch(payload: ActionPayload) {
|
protected onDispatch(payload: ActionPayload) {
|
||||||
|
// We do this to intentionally break out of the current event loop task, allowing
|
||||||
|
// us to instead wait for a more convenient time to run our updates.
|
||||||
|
setImmediate(() => this.onDispatchAsync(payload));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async onDispatchAsync(payload: ActionPayload) {
|
||||||
if (payload.action === 'MatrixActions.sync') {
|
if (payload.action === 'MatrixActions.sync') {
|
||||||
// Filter out anything that isn't the first PREPARED sync.
|
// Filter out anything that isn't the first PREPARED sync.
|
||||||
if (!(payload.prevState === 'PREPARED' && payload.state !== 'PREPARED')) {
|
if (!(payload.prevState === 'PREPARED' && payload.state !== 'PREPARED')) {
|
||||||
|
|
Loading…
Reference in a new issue