axmolengine / axmol

Axmol Engine – A Multi-platform Engine for Desktop, XBOX (UWP) and Mobile games. (A fork of Cocos2d-x-4.0)
https://axmol.dev
MIT License
922 stars 205 forks source link

JobSystem creates too many threads #2023

Closed smilediver closed 4 months ago

smilediver commented 4 months ago

JobSystem creates way too many threads. For example, on a Samsung S10e phone with 8 core CPU it creates 12 threads. On a high load these threads will be stomping on each other and on the main game thread. It should create at most hardware threads - 1 threads and leave one core free for the main thread. Though, on mobile devices it probably should be - 2 to leave one more core free for the OS and background processes, since resources there are more tight than on desktop PCs.

Also, an interesting thing to note, is that on the same Samsung S10e, other systems (like Android's Java and GPU driver) create only 4 worker threads for each system (there are 4 "Runtime worker", 4 "Binder", 4 "mali-utility-wo" threads). But it's difficult to say if they have 4 hardcoded, or if it's 8 cores / 2, or because this CPU has 4 high performance cores.

halx99 commented 4 months ago

it's configurable: https://github.com/axmolengine/axmol/blob/dev/core/base/Director.cpp#L119

halx99 commented 4 months ago

Maybe same with emscripten: clamp(hardware_concurrency(), 2, 8) ?

smilediver commented 4 months ago

Maybe same with emscripten: clamp(hardware_concurrency(), 2, 8) ?

Yeah, emscripten also should be at least -1, but I have no clue what would hardware_concurrency() report, and if it can even report a real value.