Why does web worker performance sharply decline after 30 seconds?

前端 未结 2 1417
無奈伤痛
無奈伤痛 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:34

    Tyler Ault suggested one possibility on Google+ that turned out to be very helpful.

    He speculated that using FileReaderSync in the worker thread (instead of the plain ol' async FileReader) was not providing an opportunity for garbage collection to happen.

    Changing the worker thread to use FileReader asynchronously (which intuitively seems like a performance step backwards) accelerated the process back up to just 37 seconds, right where I would expect it to be.

    I haven't heard back from Tyler yet and I'm not entirely sure I understand why garbage collection would be the culprit, but something about FileReaderSync was drastically slowing down the code.

提交回复
热议问题