Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA] perf: add performance markers for applying remote updates #53278

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,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,
Expand Down
9 changes: 9 additions & 0 deletions src/libs/actions/OnyxUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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.
Expand Down Expand Up @@ -61,33 +63,40 @@ 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');
});

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');
});

return pusherEventsPromise;
}

function applyAirshipOnyxUpdates(updates: OnyxUpdateEvent[]) {
Performance.markStart(CONST.TIMING.APPLY_AIRSHIP_UPDATES);

airshipEventsPromise = airshipEventsPromise.then(() => {
console.debug('[OnyxUpdateManager] Applying Airship updates');
});

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');
});

Expand Down
Loading