-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement parallel for_range()
for easier multithreading (reverted)
#72784
Conversation
This reminds me, is parallel |
It's fairly straightforward to write a foreach-style wrapper around a threading system, see the defunct godot/core/os/threaded_array_processor.h Lines 52 to 85 in cd015d9
However, like with the traditional function pointers that It would still be possible, it just wouldn't be a simple drop-in replacement for |
Wow! Just wow. With this PR the doors could open to quite a lot of editor optimisations as well. |
I think this is great. I just wonder if we lose something important with the removal of |
Thanks! |
I really, really think this should not have been merged. You don't need the syntactic sugar for something very seldom used that all it does is make readability worse. This is not a general purpose function, it is meant for large tasks. if you use it in any array all you will achieve is it probably being much slower than just doing a regular for loop and users will not understand why. I strongly ask to reconsider this and revert the merge. |
foreach()
for easier multithreadingfor_range()
for easier multithreading
After some discussion, the decision is to keep this with the appropriate warnings and a more explicit API: |
As a note, this PR is not a simple refactor. The original code only used the amount of CPUs available as thread count, this one uses a thread per element, which is much slower. |
For the records, there's #72716 seemigly addressing that. However, the WTP changes will be reverted until the topic can be discussed in its entirety, with some possibly coming back when there's a stronger agreement. |
for_range()
for easier multithreadingfor_range()
for easier multithreading (reverted)
This makes writing multithreaded code as easy as changing a
for
loop, without the need to refactor loop bodies into separate functions or to create intermediate structs for passing data. See the diffs ofmodules/raycast/raycast_occlusion_cull.cpp
andtests/core/threads/test_worker_thread_pool.h
for examples.Technically, I've named it
for_range()
here since it accepts integer indices.