perf: bind to this some methods in the tasks execution code path
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 4 Apr 2023 21:54:17 +0000 (23:54 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 4 Apr 2023 21:54:17 +0000 (23:54 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
.gitignore
examples/multiFunctionExample.js
src/pools/abstract-pool.ts
src/pools/selection-strategies/abstract-worker-choice-strategy.ts
src/pools/selection-strategies/worker-choice-strategy-context.ts

index 01c101b0b3c28d10c8fa2d7b0e155e29e86c2443..2dea9b803b9df157d7035b4a7f92028646931eb7 100644 (file)
@@ -76,5 +76,6 @@ package-lock.json
 .scannerwork
 *.bak
 lib
+dist
 reports/
 benchmarks/internal/results/
index 93d4e78b3d0465b35b823fd18dc2cbc203c66e31..6edc2bb7aaaa80b2d7ade610a09860785919d62d 100644 (file)
@@ -13,4 +13,4 @@ pool
   .then(res => console.log(res))
   .catch(err => console.error(err))
 
-setTimeout(pool.destroy.bind(pool), 3000)
+setTimeout(pool.destroy(pool), 3000)
index 1ce8c25ec8f3a783c2ce0802e39d81bd60e82bf2..f904af93183840b89edbf166dd02a61fa7e7ec1d 100644 (file)
@@ -73,6 +73,12 @@ export abstract class AbstractPool<
     this.checkNumberOfWorkers(this.numberOfWorkers)
     this.checkFilePath(this.filePath)
     this.checkPoolOptions(this.opts)
+
+    this.chooseWorker.bind(this)
+    this.internalExecute.bind(this)
+    this.checkAndEmitBusy.bind(this)
+    this.sendToWorker.bind(this)
+
     this.setupHook()
 
     for (let i = 1; i <= this.numberOfWorkers; i++) {
index 5c2a553d187b92fe5793fac750a7ae2c5d0d9e82..3a5d6e04a3ddd46e0e78e8d8a57062e8e9ba966c 100644 (file)
@@ -35,6 +35,7 @@ export abstract class AbstractWorkerChoiceStrategy<
     protected readonly pool: IPoolInternal<Worker, Data, Response>
   ) {
     this.isDynamicPool = this.pool.type === PoolType.DYNAMIC
+    this.choose.bind(this)
   }
 
   /** {@inheritDoc} */
index bd616a54d666ffc3372d09e040686e3e9aa1aca2..1564e0f0f73e1c41d6da2f9d157620439f3489f8 100644 (file)
@@ -36,6 +36,7 @@ export class WorkerChoiceStrategyContext<
     private readonly createWorkerCallback: () => number,
     workerChoiceStrategy: WorkerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN
   ) {
+    this.execute.bind(this)
     this.setWorkerChoiceStrategy(workerChoiceStrategy)
   }