From de372e1af1227dbfb4d0ab9b6b85c2e0963753c2 Mon Sep 17 00:00:00 2001 From: Adam Horodyski Date: Tue, 30 Jul 2024 14:52:57 +0200 Subject: [PATCH 1/2] fix: improve perf of isActionOfType by limiting calls to the includes --- src/libs/ReportActionsUtils.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 1a43877c91e07..96a38f662ef1d 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -189,7 +189,14 @@ function isActionOfType( ): action is { [K in keyof T]: ReportAction; }[number] { - return actionNames.includes(action?.actionName as T[number]); + const actionName = action?.actionName as T[number]; + + // This is purely a performance optimization to limit the 'includes()' calls on Hermes + if (actionNames.length === 1) { + return actionNames[0] === actionName; + } + + return actionNames.includes(actionName); } function getOriginalMessage(reportAction: OnyxInputOrEntry>): OriginalMessage | undefined { From de7aec3576486dde2db5e7962dfd629c82b98890 Mon Sep 17 00:00:00 2001 From: Adam Horodyski Date: Mon, 5 Aug 2024 17:20:28 +0200 Subject: [PATCH 2/2] chore: rework the body of isActionOfType to always rely on a basic for loop --- src/libs/ReportActionsUtils.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 96a38f662ef1d..e49079de70188 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -192,11 +192,13 @@ function isActionOfType( const actionName = action?.actionName as T[number]; // This is purely a performance optimization to limit the 'includes()' calls on Hermes - if (actionNames.length === 1) { - return actionNames[0] === actionName; + for (const i of actionNames) { + if (i === actionName) { + return true; + } } - return actionNames.includes(actionName); + return false; } function getOriginalMessage(reportAction: OnyxInputOrEntry>): OriginalMessage | undefined {