From: Jérôme Benoit Date: Mon, 2 Sep 2024 09:35:51 +0000 (+0200) Subject: perf: optimize backpressure task(s) stealing conditions X-Git-Tag: v4.2.10~9 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=9df97afd77c24c8850e0d56eae3d3c66df181981;p=poolifier.git perf: optimize backpressure task(s) stealing conditions Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 1a2c8bf3..b883eb96 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -265,16 +265,16 @@ export abstract class AbstractPool< workerNodeA.usage.tasks.queued - workerNodeB.usage.tasks.queued ) for (const [workerNodeKey, workerNode] of workerNodes.entries()) { + if (sourceWorkerNode.usage.tasks.queued === 0) { + break + } if ( - sourceWorkerNode.usage.tasks.queued > 0 && workerNode.info.id !== workerId && + !workerNode.info.backPressureStealing && workerNode.usage.tasks.queued < // eslint-disable-next-line @typescript-eslint/no-non-null-assertion this.opts.tasksQueueOptions!.size! - sizeOffset ) { - if (workerNode.info.backPressureStealing) { - continue - } workerNode.info.backPressureStealing = true this.stealTask(sourceWorkerNode, workerNodeKey) workerNode.info.backPressureStealing = false