From 9df97afd77c24c8850e0d56eae3d3c66df181981 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 2 Sep 2024 11:35:51 +0200 Subject: [PATCH] perf: optimize backpressure task(s) stealing conditions MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/pools/abstract-pool.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 -- 2.34.1