perf: improve node eligibility branching on worker choice strategies
[poolifier.git] / src / pools / selection-strategies / interleaved-weighted-round-robin-worker-choice-strategy.ts
index 86a7f5ca8f801c6b5e98dc380e9ee5dea80d37e3..e37543820593a68b6860e7b597c40919c8866e9d 100644 (file)
@@ -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
         }