diff options
author | Jacques Lucke <jacques@blender.org> | 2022-09-20 11:59:12 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2022-09-20 12:08:05 +0300 |
commit | 5c81d3bd4691214164a7f071d239ef6c84dba8dc (patch) | |
tree | cbab752ca58da40b45c15540707a2b0a22d769da /source/blender/blenlib/intern/lazy_threading.cc | |
parent | 7a239812ca55153fc9751b6a87bc5c4deb76456b (diff) |
Geometry Nodes: improve evaluator with lazy threading
In large node setup the threading overhead was sometimes very significant.
That's especially true when most nodes do very little work.
This commit improves the scheduling by not using multi-threading in many
cases unless it's likely that it will be worth it. For more details see the comments
in `BLI_lazy_threading.hh`.
Differential Revision: https://developer.blender.org/D15976
Diffstat (limited to 'source/blender/blenlib/intern/lazy_threading.cc')
-rw-r--r-- | source/blender/blenlib/intern/lazy_threading.cc | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/lazy_threading.cc b/source/blender/blenlib/intern/lazy_threading.cc new file mode 100644 index 00000000000..803fd81a96d --- /dev/null +++ b/source/blender/blenlib/intern/lazy_threading.cc @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "BLI_lazy_threading.hh" +#include "BLI_vector.hh" + +namespace blender::lazy_threading { + +/** + * This is a #RawVector so that it can be destructed after Blender checks for memory leaks. + */ +thread_local RawVector<FunctionRef<void()>, 0> hint_receivers; + +void send_hint() +{ + for (const FunctionRef<void()> &fn : hint_receivers) { + fn(); + } +} + +HintReceiver::HintReceiver(const FunctionRef<void()> fn) +{ + hint_receivers.append(fn); +} + +HintReceiver::~HintReceiver() +{ + hint_receivers.pop_last(); +} + +} // namespace blender::lazy_threading |