From be939b9d4513feb07359657b7eab70ec8a1b30a2 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Tue, 15 Aug 2023 08:50:34 +0700 Subject: [PATCH] chore: fastest way to create deltas array --- packages/fork-choice/src/protoArray/computeDeltas.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/fork-choice/src/protoArray/computeDeltas.ts b/packages/fork-choice/src/protoArray/computeDeltas.ts index 09f2cf05f1f5..8301c1e77a75 100644 --- a/packages/fork-choice/src/protoArray/computeDeltas.ts +++ b/packages/fork-choice/src/protoArray/computeDeltas.ts @@ -19,7 +19,11 @@ export function computeDeltas( newBalances: EffectiveBalanceIncrements, equivocatingIndices: Set ): number[] { - const deltas = Array(numProtoNodes).fill(0); + const deltas = new Array(numProtoNodes); + for (let i = 0; i < numProtoNodes; i++) { + deltas[i] = 0; + } + // avoid creating new variables in the loop to potentially reduce GC pressure let oldBalance, newBalance: number; let currentIndex, nextIndex: number | null;