From 47c156ffc12eb8a8baba721630bb2b1479ff7e7a Mon Sep 17 00:00:00 2001 From: Paul <108695806+pxrl@users.noreply.github.com> Date: Fri, 4 Oct 2024 12:09:02 +0200 Subject: [PATCH] improve(relayer): Defer deposit version computation (#1847) getUnfilledDeposits() currently unconditionally computes the deposit version (i.e. the ConfigStore VERSION value applicable at the deposit quoteTimestamp), and then filters out all the deposits that have been filled. Determining the relevant version implies a lot of Array.find() calls, all of which is wasted when the object is subsequently discarded. --- src/utils/FillUtils.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/utils/FillUtils.ts b/src/utils/FillUtils.ts index cce7d59b9..010afdc67 100644 --- a/src/utils/FillUtils.ts +++ b/src/utils/FillUtils.ts @@ -32,11 +32,14 @@ export function getUnfilledDeposits( return deposits .map((deposit) => { - const version = hubPoolClient.configStoreClient.getConfigStoreVersionForTimestamp(deposit.quoteTimestamp); const { unfilledAmount, invalidFills } = destinationClient.getValidUnfilledAmountForDeposit(deposit); - return { deposit, version, unfilledAmount, invalidFills }; + return { deposit, unfilledAmount, invalidFills }; }) - .filter(({ unfilledAmount }) => unfilledAmount.gt(bnZero)); + .filter(({ unfilledAmount }) => unfilledAmount.gt(bnZero)) + .map(({ deposit, ...rest }) => { + const version = hubPoolClient.configStoreClient.getConfigStoreVersionForTimestamp(deposit.quoteTimestamp); + return { deposit, ...rest, version }; + }); } export function getAllUnfilledDeposits(