From: Jérôme Benoit Date: Fri, 22 Dec 2023 21:30:32 +0000 (+0100) Subject: perf: avoid branching on pool type X-Git-Tag: v3.1.10~3 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=9d9fb7b64a28d150583fe1bcd895893f6736d9d4;p=poolifier.git perf: avoid branching on pool type Signed-off-by: Jérôme Benoit --- diff --git a/src/circular-array.ts b/src/circular-array.ts index 8f545179..cc58d8ac 100644 --- a/src/circular-array.ts +++ b/src/circular-array.ts @@ -5,6 +5,7 @@ export const DEFAULT_CIRCULAR_ARRAY_SIZE = 1024 /** * Array with a maximum length and shifting items when full. * + * @typeParam T - Type of items. * @internal */ export class CircularArray extends Array { diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 9045b063..617d0d8b 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -1178,9 +1178,7 @@ export abstract class AbstractPool< * * @returns Whether to create a dynamic worker or not. */ - private shallCreateDynamicWorker (): boolean { - return this.type === PoolTypes.dynamic && !this.full && this.internalBusy() - } + protected abstract shallCreateDynamicWorker (): boolean /** * Sends a message to worker given its worker node key. diff --git a/src/pools/cluster/dynamic.ts b/src/pools/cluster/dynamic.ts index 9636b423..ce28e421 100644 --- a/src/pools/cluster/dynamic.ts +++ b/src/pools/cluster/dynamic.ts @@ -38,6 +38,11 @@ export class DynamicClusterPool< ) } + /** @inheritDoc */ + protected shallCreateDynamicWorker (): boolean { + return !this.full && this.internalBusy() + } + /** @inheritDoc */ protected get type (): PoolType { return PoolTypes.dynamic diff --git a/src/pools/cluster/fixed.ts b/src/pools/cluster/fixed.ts index 545238b0..b7bf9c1a 100644 --- a/src/pools/cluster/fixed.ts +++ b/src/pools/cluster/fixed.ts @@ -89,6 +89,11 @@ export class FixedClusterPool< this.workerNodes[workerNodeKey].worker.off('message', listener) } + /** @inheritDoc */ + protected shallCreateDynamicWorker (): boolean { + return false + } + /** @inheritDoc */ protected get type (): PoolType { return PoolTypes.fixed diff --git a/src/pools/thread/dynamic.ts b/src/pools/thread/dynamic.ts index cd9d2325..cf317ca2 100644 --- a/src/pools/thread/dynamic.ts +++ b/src/pools/thread/dynamic.ts @@ -38,6 +38,11 @@ export class DynamicThreadPool< ) } + /** @inheritDoc */ + protected shallCreateDynamicWorker (): boolean { + return !this.full && this.internalBusy() + } + /** @inheritDoc */ protected get type (): PoolType { return PoolTypes.dynamic diff --git a/src/pools/thread/fixed.ts b/src/pools/thread/fixed.ts index 13df2b5c..088d72c9 100644 --- a/src/pools/thread/fixed.ts +++ b/src/pools/thread/fixed.ts @@ -108,6 +108,11 @@ export class FixedThreadPool< ) } + /** @inheritDoc */ + protected shallCreateDynamicWorker (): boolean { + return false + } + /** @inheritDoc */ protected get type (): PoolType { return PoolTypes.fixed diff --git a/src/pools/utils.ts b/src/pools/utils.ts index c7ab2d1e..619e2061 100644 --- a/src/pools/utils.ts +++ b/src/pools/utils.ts @@ -164,7 +164,6 @@ export const checkWorkerNodeArguments = ( * @param measurementStatistics - The measurement statistics to update. * @param measurementRequirements - The measurement statistics requirements. * @param measurementValue - The measurement value. - * @param numberOfMeasurements - The number of measurements. * @internal */ const updateMeasurementStatistics = (