perf: use a single array to store pool workers and their related data
[poolifier.git] / src / pools / selection-strategies / weighted-round-robin-worker-choice-strategy.ts
index 1af7e6568f19a0705df40014ff404e91645dfd09..9ee4fa656632c7fcdfc982e5b7cf40b794d57e97 100644 (file)
@@ -67,8 +67,7 @@ export class WeightedRoundRobinWorkerChoiceStrategy<
 
   /** {@inheritDoc} */
   public choose (): Worker {
-    const chosenWorker = this.pool.workers.get(this.currentWorkerId)
-      ?.worker as Worker
+    const chosenWorker = this.pool.workers[this.currentWorkerId]?.worker
     if (this.isDynamicPool && !this.workersTaskRunTime.has(chosenWorker)) {
       this.initWorkerTaskRunTime(chosenWorker)
     }
@@ -86,11 +85,11 @@ export class WeightedRoundRobinWorkerChoiceStrategy<
       )
     } else {
       this.currentWorkerId =
-        this.currentWorkerId === this.pool.workers.size - 1
+        this.currentWorkerId === this.pool.workers.length - 1
           ? 0
           : this.currentWorkerId + 1
       this.setWorkerTaskRunTime(
-        this.pool.workers.get(this.currentWorkerId)?.worker as Worker,
+        this.pool.workers[this.currentWorkerId]?.worker,
         workerTaskWeight,
         0
       )
@@ -99,8 +98,8 @@ export class WeightedRoundRobinWorkerChoiceStrategy<
   }
 
   private initWorkersTaskRunTime (): void {
-    for (const value of this.pool.workers.values()) {
-      this.initWorkerTaskRunTime(value.worker)
+    for (const workerItem of this.pool.workers) {
+      this.initWorkerTaskRunTime(workerItem.worker)
     }
   }