diff options
author | Hans Goudey <h.goudey@me.com> | 2022-05-09 19:21:37 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-05-09 19:21:50 +0300 |
commit | c2737913dbe7dd9b70d6fb01ef9a6487f94064f9 (patch) | |
tree | d82345d55d490aaaabbf3e685c1f2e59cf92054a /source/blender | |
parent | 892562b7bf9c3f5ff82947eae38116d8c0fdcaea (diff) |
BLI: Avoid invoking tbb for small parallel_reduce calls
Apply a change similar to e1309030603980c6b2f33486 for
`parallel_reduce`, just like `parallel_for`. I measured a performance
improvement in viewport FPS of at least 10% with 1 million small
instances (one bottleneck was computing many small bounding boxes).
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenlib/BLI_task.hh | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/source/blender/blenlib/BLI_task.hh b/source/blender/blenlib/BLI_task.hh index d87a86ce696..904dea66f7a 100644 --- a/source/blender/blenlib/BLI_task.hh +++ b/source/blender/blenlib/BLI_task.hh @@ -77,17 +77,19 @@ Value parallel_reduce(IndexRange range, const Reduction &reduction) { #ifdef WITH_TBB - return tbb::parallel_reduce( - tbb::blocked_range<int64_t>(range.first(), range.one_after_last(), grain_size), - identity, - [&](const tbb::blocked_range<int64_t> &subrange, const Value &ident) { - return function(IndexRange(subrange.begin(), subrange.size()), ident); - }, - reduction); + if (range.size() >= grain_size) { + return tbb::parallel_reduce( + tbb::blocked_range<int64_t>(range.first(), range.one_after_last(), grain_size), + identity, + [&](const tbb::blocked_range<int64_t> &subrange, const Value &ident) { + return function(IndexRange(subrange.begin(), subrange.size()), ident); + }, + reduction); + } #else UNUSED_VARS(grain_size, reduction); - return function(range, identity); #endif + return function(range, identity); } /** |