From aa2879d6e85cf0278dcb36030d6c64306e6c0704 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Mon, 23 Mar 2020 06:42:08 -0700 Subject: [PATCH] Remove double async wrapping Summary: Our usage of requestIdleCallback (probably) causes more trouble than it solves: 1. It makes sure everything is processed asynchronously. But since everything is arriving over a network stack, that is already the case without wrapping it again to run on a separate event loop tick 2. The timeout we set before `500` forces the app to give _more_ priority to message processing instead of less 3. In a next diff (D20151700) in this stack we will make sure that messages are not processed immediately, but simple stored, which should not be significantly more expensive (probably even cheaper) than scheduling another tick on the event loop Reviewed By: jknoxville Differential Revision: D20557104 fbshipit-source-id: 6cc10ba537e3cb5f31e6c32e1fdeb57c20f06f17 --- desktop/app/src/Client.tsx | 9 --------- desktop/app/src/server.tsx | 18 ++++++++++++------ 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/desktop/app/src/Client.tsx b/desktop/app/src/Client.tsx index 472307218..694ded944 100644 --- a/desktop/app/src/Client.tsx +++ b/desktop/app/src/Client.tsx @@ -121,7 +121,6 @@ export default class Client extends EventEmitter { logger: Logger; lastSeenDeviceList: Array; broadcastCallbacks: Map>>; - rIC: any; requestCallbacks: Map< number, @@ -167,14 +166,6 @@ export default class Client extends EventEmitter { } const client = this; - // node.js doesn't support requestIdleCallback - this.rIC = - typeof window === 'undefined' || !window.requestIdleCallback - ? (cb: Function, _: any) => { - cb(); - } - : window.requestIdleCallback.bind(window); - if (conn) { conn.connectionStatus().subscribe({ onNext(payload) { diff --git a/desktop/app/src/server.tsx b/desktop/app/src/server.tsx index dc9e9d8df..cc76e4388 100644 --- a/desktop/app/src/server.tsx +++ b/desktop/app/src/server.tsx @@ -252,7 +252,10 @@ class Server extends EventEmitter { socket, {app, os, device, device_id, sdk_version}, {csr, csr_path}, - ); + ).then(client => { + return (resolvedClient = client); + }); + let resolvedClient: Client | undefined; socket.connectionStatus().subscribe({ onNext(payload) { @@ -269,12 +272,15 @@ class Server extends EventEmitter { }); return { - fireAndForget: (payload: {data: string}) => - client.then(client => { - client.rIC(() => client.onMessage(payload.data), { - timeout: 500, + fireAndForget: (payload: {data: string}) => { + if (resolvedClient) { + resolvedClient.onMessage(payload.data); + } else { + client.then(client => { + client.onMessage(payload.data); }); - }), + } + }, }; };