From 1bb1e00208d76af887d82531ca4b4daf3562d37d Mon Sep 17 00:00:00 2001 From: Adam Horodyski Date: Thu, 28 Nov 2024 19:58:23 +0100 Subject: [PATCH] feat: add perf markers to applying remote updates --- src/CONST.ts | 3 +++ src/libs/actions/OnyxUpdates.ts | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/src/CONST.ts b/src/CONST.ts index ff4a9f2de91a..52fe22a661cb 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -1305,6 +1305,9 @@ const CONST = { SIDEBAR_LOADED: 'sidebar_loaded', LOAD_SEARCH_OPTIONS: 'load_search_options', SEND_MESSAGE: 'send_message', + APPLY_AIRSHIP_UPDATES: 'apply_airship_updates', + APPLY_PUSHER_UPDATES: 'apply_pusher_updates', + APPLY_HTTPS_UPDATES: 'apply_https_updates', COLD: 'cold', WARM: 'warm', REPORT_ACTION_ITEM_LAYOUT_DEBOUNCE_TIME: 1500, diff --git a/src/libs/actions/OnyxUpdates.ts b/src/libs/actions/OnyxUpdates.ts index 1ba50d08e449..52dfa9dfd742 100644 --- a/src/libs/actions/OnyxUpdates.ts +++ b/src/libs/actions/OnyxUpdates.ts @@ -3,6 +3,7 @@ import Onyx from 'react-native-onyx'; import type {Merge} from 'type-fest'; import Log from '@libs/Log'; import * as SequentialQueue from '@libs/Network/SequentialQueue'; +import Performance from '@libs/Performance'; import PusherUtils from '@libs/PusherUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -26,6 +27,7 @@ let pusherEventsPromise = Promise.resolve(); let airshipEventsPromise = Promise.resolve(); function applyHTTPSOnyxUpdates(request: Request, response: Response) { + Performance.markStart(CONST.TIMING.APPLY_HTTPS_UPDATES); console.debug('[OnyxUpdateManager] Applying https update'); // For most requests we can immediately update Onyx. For write requests we queue the updates and apply them after the sequential queue has flushed to prevent a replay effect in // the UI. See https://github.com/Expensify/App/issues/12775 for more info. @@ -61,12 +63,15 @@ function applyHTTPSOnyxUpdates(request: Request, response: Response) { return Promise.resolve(); }) .then(() => { + Performance.markEnd(CONST.TIMING.APPLY_HTTPS_UPDATES); console.debug('[OnyxUpdateManager] Done applying HTTPS update'); return Promise.resolve(response); }); } function applyPusherOnyxUpdates(updates: OnyxUpdateEvent[]) { + Performance.markStart(CONST.TIMING.APPLY_PUSHER_UPDATES); + pusherEventsPromise = pusherEventsPromise.then(() => { console.debug('[OnyxUpdateManager] Applying pusher update'); }); @@ -74,6 +79,7 @@ function applyPusherOnyxUpdates(updates: OnyxUpdateEvent[]) { pusherEventsPromise = updates .reduce((promise, update) => promise.then(() => PusherUtils.triggerMultiEventHandler(update.eventType, update.data)), pusherEventsPromise) .then(() => { + Performance.markEnd(CONST.TIMING.APPLY_PUSHER_UPDATES); console.debug('[OnyxUpdateManager] Done applying Pusher update'); }); @@ -81,6 +87,8 @@ function applyPusherOnyxUpdates(updates: OnyxUpdateEvent[]) { } function applyAirshipOnyxUpdates(updates: OnyxUpdateEvent[]) { + Performance.markStart(CONST.TIMING.APPLY_AIRSHIP_UPDATES); + airshipEventsPromise = airshipEventsPromise.then(() => { console.debug('[OnyxUpdateManager] Applying Airship updates'); }); @@ -88,6 +96,7 @@ function applyAirshipOnyxUpdates(updates: OnyxUpdateEvent[]) { airshipEventsPromise = updates .reduce((promise, update) => promise.then(() => Onyx.update(update.data)), airshipEventsPromise) .then(() => { + Performance.markEnd(CONST.TIMING.APPLY_AIRSHIP_UPDATES); console.debug('[OnyxUpdateManager] Done applying Airship updates'); });