diff options
Diffstat (limited to 'source/blender/blenlib/intern/task.c')
-rw-r--r-- | source/blender/blenlib/intern/task.c | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/source/blender/blenlib/intern/task.c b/source/blender/blenlib/intern/task.c index 2f6c88c128a..6cdaec97d9a 100644 --- a/source/blender/blenlib/intern/task.c +++ b/source/blender/blenlib/intern/task.c @@ -1064,22 +1064,28 @@ BLI_INLINE void task_parallel_range_calc_chunk_size(const TaskParallelSettings * chunk_size = settings->min_iter_per_thread; } else { - /* Basic heuristic to avoid threading on low amount of items. We could make that limit - * configurable in settings too... */ - if (tot_items > 0 && tot_items < 256) { - chunk_size = tot_items; - } - /* NOTE: The idea here is to compensate for rather measurable threading + /* Multiplier used in heuristics below to define "optimal" chunk size. + * The idea here is to increase the chunk size to compensate for a rather measurable threading * overhead caused by fetching tasks. With too many CPU threads we are starting - * to spend too much time in those overheads. */ - else if (num_tasks > 32) { - chunk_size = 128; - } - else if (num_tasks > 16) { - chunk_size = 64; - } - else { - chunk_size = 32; + * to spend too much time in those overheads. + * First values are: 1 if num_tasks < 16; + * else 2 if num_tasks < 32; + * else 3 if num_tasks < 48; + * else 4 if num_tasks < 64; + * etc. + * Note: If we wanted to keep the 'power of two' multiplier, we'd need something like: + * 1 << max_ii(0, (int)(sizeof(int) * 8) - 1 - bitscan_reverse_i(num_tasks) - 3) + */ + const int num_tasks_factor = max_ii(1, num_tasks >> 3); + + /* We could make that 'base' 32 number configurable in TaskParallelSettings too, or maybe just + * always use that heuristic using TaskParallelSettings.min_iter_per_thread as basis? */ + chunk_size = 32 * num_tasks_factor; + + /* Basic heuristic to avoid threading on low amount of items. + * We could make that limit configurable in settings too. */ + if (tot_items > 0 && tot_items < max_ii(256, chunk_size * 2)) { + chunk_size = tot_items; } } |