From 1086026a2542abdcd0c5569d9afbfb8c2e628276 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 4 Apr 2023 23:54:17 +0200 Subject: [PATCH] perf: bind to this some methods in the tasks execution code path MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .gitignore | 1 + examples/multiFunctionExample.js | 2 +- src/pools/abstract-pool.ts | 6 ++++++ .../selection-strategies/abstract-worker-choice-strategy.ts | 1 + .../selection-strategies/worker-choice-strategy-context.ts | 1 + 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 01c101b0..2dea9b80 100644 --- a/.gitignore +++ b/.gitignore @@ -76,5 +76,6 @@ package-lock.json .scannerwork *.bak lib +dist reports/ benchmarks/internal/results/ diff --git a/examples/multiFunctionExample.js b/examples/multiFunctionExample.js index 93d4e78b..6edc2bb7 100644 --- a/examples/multiFunctionExample.js +++ b/examples/multiFunctionExample.js @@ -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) diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 1ce8c25e..f904af93 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -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++) { diff --git a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts index 5c2a553d..3a5d6e04 100644 --- a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts @@ -35,6 +35,7 @@ export abstract class AbstractWorkerChoiceStrategy< protected readonly pool: IPoolInternal ) { this.isDynamicPool = this.pool.type === PoolType.DYNAMIC + this.choose.bind(this) } /** {@inheritDoc} */ diff --git a/src/pools/selection-strategies/worker-choice-strategy-context.ts b/src/pools/selection-strategies/worker-choice-strategy-context.ts index bd616a54..1564e0f0 100644 --- a/src/pools/selection-strategies/worker-choice-strategy-context.ts +++ b/src/pools/selection-strategies/worker-choice-strategy-context.ts @@ -36,6 +36,7 @@ export class WorkerChoiceStrategyContext< private readonly createWorkerCallback: () => number, workerChoiceStrategy: WorkerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN ) { + this.execute.bind(this) this.setWorkerChoiceStrategy(workerChoiceStrategy) } -- 2.34.1