perf: improve node eligibility branching on worker choice strategies
[poolifier.git] / src / pools / selection-strategies / interleaved-weighted-round-robin-worker-choice-strategy.ts
index 0fc1e0da3da3e8319cb71e90308e324e64fa82bd..e37543820593a68b6860e7b597c40919c8866e9d 100644 (file)
@@ -60,7 +60,7 @@ export class InterleavedWeightedRoundRobinWorkerChoiceStrategy<
 
   /** @inheritDoc */
   public choose (): number | undefined {
-    let roundId: number = this.roundId
+    let roundId!: number
     let workerNodeId: number | undefined
     for (
       let roundIndex = this.roundId;
@@ -74,12 +74,12 @@ export class InterleavedWeightedRoundRobinWorkerChoiceStrategy<
         workerNodeKey < this.pool.workerNodes.length;
         workerNodeKey++
       ) {
+        if (!this.isWorkerNodeEligible(workerNodeKey)) {
+          continue
+        }
         const workerWeight =
           this.opts.weights?.[workerNodeKey] ?? this.defaultWorkerWeight
-        if (
-          this.isWorkerNodeEligible(workerNodeKey) &&
-          workerWeight >= this.roundWeights[roundIndex]
-        ) {
+        if (workerWeight >= this.roundWeights[roundIndex]) {
           workerNodeId = workerNodeKey
           break
         }