Spawn WebWorker if necessary or reusing the same?

I am creating a WebGL game that requires WebWorker to do some processing on the grid, preventing it from lagging in the main thread.

My question is: is it better to create / create new WebWorkers if necessary and complete them when completing a task or create one permanent WebWorker that queues for work with the grid? Does irregular (and destroy) new WebWorkers create a lot of overhead?

The main advantage of their creation, if necessary, is the simultaneous execution of several operations without the absence of a pending processing process, which means faster grid generation.

Thanks for any advice so I can optimize my code for better performance. Thank!

+4
source share
1 answer

This is not a WebGL question, it's just a general WebWorker question. From the head, although it depends. Workers are just threads. If your threads are busy 100% of the time (without waiting for I / O or user input or the next frame), you will not get any speed if you have more threads than cores.

In other words, if you have 2 cores and 3 threads, each of which works without waiting for anything but 1 core, 1 thread will be executed 100% of the time, and the other core will start each of the other threads for 50 % of the time, Total time will be the same as if you combined 2 threads into 1.

, , , JavaScript .

, , . , 200meg ( JSON) 100meg, ( JSON Float32Arrays ..). , , 1gig ( 100- )

, 10 . , 1 ( 10 ), 300 (200 JSON, 100 ). 3 . , .

, , , 1,2 . JSON (200meg) Float32Arrays (100meg), Float32Arrays , .

3 ,

  • . . .

    , javascript?

  • .

    . , .

  • .

+2

Source: https://habr.com/ru/post/1532520/


All Articles