From 282367797723be52edecd42913202926d36b52f6 Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Thu, 25 Apr 2024 21:56:24 -0600 Subject: [PATCH] Tweak threshold --- flox/core.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/flox/core.py b/flox/core.py index f6d65121..fcecff23 100644 --- a/flox/core.py +++ b/flox/core.py @@ -271,8 +271,14 @@ def chunk_unique(labels, slicer, nlabels, label_is_present=None): return uniques # TODO: needs a better heuristic - if nlabels < 2 * approx_chunk_size: - logger.debug("Using threadpool since %s < 5 * %s", nlabels, approx_chunk_size) + THRESHOLD = 2 + if nlabels < THRESHOLD * approx_chunk_size: + logger.debug( + "Using threadpool since num_labels %s < %d * chunksize %s", + nlabels, + THRESHOLD, + approx_chunk_size, + ) with ThreadPoolExecutor() as executor: futures = [ executor.submit(chunk_unique, labels, slicer, nlabels) @@ -281,6 +287,12 @@ def chunk_unique(labels, slicer, nlabels, label_is_present=None): cols = tuple(f.result() for f in futures) else: + logger.debug( + "Using serial loop since num_labels %s > %d * chunksize %s", + nlabels, + THRESHOLD, + approx_chunk_size, + ) cols = [] # Add one to handle the -1 sentinel value label_is_present = np.zeros((nlabels + 1,), dtype=bool)