Steps to reproduce
If new Function constructor is used to create a function from source in a web worker than this function performs significantly slower than if “static” function is used instead. I did not manage to profile the case since Edge Dev Tools provide no profiling for Web Workers. However, I have a Benchmarks Page that shows the issue.
If parallel-dynamic (or threadsjs) together with Mandelbrot is selected (unselect the other test cases like Knight-Tours and Montecarlo) the benchmark even performs slower (800s) than if the computation is performed synchronously (512s). The implementation serializes the Function used to compute a single line in the Mandelbrot and reconstructs it using
new Function in the Web Worker.
If instead parallel-transpiled (or parallel.js) is selected, the test outperforms (132) the synchronous implementation by a multitude (as it should be). The code used for computing the Mandelbrot line is exactly the same. The only difference is that the function is defined statically in the web worker js file.
I could not reproduce the issue if the Function constructor is used inside the ui-thread. So I assume it is related to web workers in combination with dynamic function constructs.