Why does web worker performance sharply decline after 30 seconds?

前端 未结 2 1326
無奈伤痛
無奈伤痛 2021-02-02 09:12

I\'m trying to improve the performance of a script when executed in a web worker. It\'s designed to parse large text files in the browser without crashing. Everything works pret

2条回答
  •  北海茫月
    2021-02-02 09:46

    What hardware are you running on? You may be running into cache thrashing problems with your CPU. For example if the CPU cache is 1MB per core (just an example) and you start trying to work with data continually replacing the cache (cache misses) then you will suffer slow downs - this is quite common with MT systems. This is common in IO transfers too. Also these systems tend to have some OS overheads for the thread contexts as well. So if lots of threads are being spawned you may be spending more time managing the contexts than the thread is 'doing work'. I haven't yet looked at your code, so I could be way off - but my guess is on the memory issue just due to what your application is doing. :)

    Oh. How to fix. Try making the blocks of execution small single chunks that match the hardware. Minimize the amount of threads in use at once - try to keep them 2-3x the amount of cores you have in the hardware (this really depends what sort of hw you have). Hope that helps.

提交回复
热议问题