From: Jérôme Benoit Date: Tue, 4 Apr 2023 21:54:17 +0000 (+0200) Subject: perf: bind to this some methods in the tasks execution code path X-Git-Tag: v2.4.1~13 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=1086026a2542abdcd0c5569d9afbfb8c2e628276;p=poolifier.git perf: bind to this some methods in the tasks execution code path Signed-off-by: Jérôme Benoit --- 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) }