From 8b498989fd937b7d1f8a0020c3db35c558d15f0d Mon Sep 17 00:00:00 2001 From: Paul <108695806+pxrl@users.noreply.github.com> Date: Wed, 2 Oct 2024 16:48:50 +0200 Subject: [PATCH] improve(relayer): Defer deposit version computation 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(