-
-
Notifications
You must be signed in to change notification settings - Fork 22.4k
[Web] Use actual PThread
pool size for get_default_thread_pool_size()
#104458
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
base: master
Are you sure you want to change the base?
[Web] Use actual PThread
pool size for get_default_thread_pool_size()
#104458
Conversation
bfe4570
to
7a83399
Compare
For reference, here's the PR #54499 that introduced the static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have an answer directly for https://github.com/godotengine/godot/pull/104458/files#r2008222268 though.
PThread
pool size for get_default_thread_pool_size()
486fe27
to
7ead9c3
Compare
Pushed again to fix lint issues from suggested changes in the review. |
7ead9c3
to
91db595
Compare
Hi @marcosc90 , thank you for looking into this issue. I will start with some context, but first, I didn't realize you could pass an expression as Now for some context... Most browsers have a hard cap on threads, historically, that cap has been quite low. On the web, threads are spawned asynchronously, so code like:
Will produce a deadlock. This is why emscripten introduced the PTHREAD_POOL_SIZE option. But this means that any thread spawned in addition to the PTHREAD_POOL_SIZE, will still cause deadlocks when occurring in the above scenario. The issue we historically had with the godot thread pool was it filling the emscripten thread pool size, causing deadlocks in other parts of the engine (where the aformentioned start/join was used, sometimes by third party libraries). So, in general, we need to find a good trade-off, and that's not easy to find. With this in mind, I suggest we may just want to make both values customizable via JS via We can set those value to a reasonable defeault (8 for the emscripten pool, 4 for the godot pool). We can make the value customizable when exporting via the editor by adding the values to the config in EditorExportPlatformWeb We can also optionally add more logic (in a follow up PR) to EditorExportPlatformWeb to throw an error/warning if values are set too small for the current project settings. We could also explore building with PTHREAD_POOL_SIZE_STRICT but that probably deserves its own discussion. Let me know what you think. |
Hi @Faless, that sounds good to me since currently on my custom build I'm using some custom values, so making the customizable would be great. I'm not yet familiar with how all the settings work in godot, to confirm, do you mean adding those configs to the export template settings? Just below Thread Support, adding something like:
|
Yes, that's indeed what I've been thinking |
I've been quite busy, I'll try to get this done during the weekend. |
91db595
to
b182993
Compare
Please apply the following patch so we don't pollute |
b182993
to
5d950cb
Compare
Much better, thanks @Faless . I was looking for a better way, but was still figuring it out how all the code glues together. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the docs, you will need to run Godot from the engine root with the --doctool
argument. It will automatically generate the correct docs bindings in the correct place so you don't trigger the CI error. See: https://docs.godotengine.org/en/latest/contributing/documentation/updating_the_class_reference.html#updating-class-reference-when-working-on-the-engine
I have made some rough suggestions, but this is outside my area of expertise, so the content may not be exactly accurate
5d950cb
to
dec04c6
Compare
Thanks @clayjohn |
dec04c6
to
1692e6d
Compare
1692e6d
to
ae0faab
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me now. CC @Faless For final confirmation
fixes #104428
This resolves a freeze in WebAssembly builds when
physics/3d/run_on_separate_thread=true
and threading is enabled.Previously,
get_default_thread_pool_size()
inOS_Web
was hardcoded to return 1, which caused physics step group tasks to stall. The only available worker was occupied by this long-lived task:godot/servers/physics_server_3d_wrap_mt.cpp
Lines 42 to 47 in 2303ce8
As a result, the following task
godot/modules/godot_physics_3d/godot_step_3d.cpp
Line 347 in 2303ce8
would never execute, leading to a deadlock. This patch replaces the hardcoded value with a dynamic call to a JS hook that reflects the available pthread pool size at runtime.
bugsquad edit: fixes #104004