developit / task-worklet

Task Worklet: explainer, polyfill and demos.
Apache License 2.0
275 stars 4 forks source link

Eval() in web workers / task worklet #13

Closed TimvanScherpenzeel closed 5 years ago

TimvanScherpenzeel commented 5 years ago

Hi,

Thank you for this polyfill / proposal.

I was wondering about the use of eval() in web workers. As you probably know any code ran through eval is very unlikely to be optimised by V8 (see https://github.com/petkaantonov/bluebird/wiki/Optimization-killers). Would you know if this is also the case for eval in web workers? If so, wouldn't it make sense to avoid heavy long running code in the worker (that normally would become hot in the main thread after a short time)? Doesn't that defeat the whole point of using a worker in the first place (seeing as there is a reasonably significant cost to spawning and thread hopping)? Making a worker worth its weight in that case would be a significant challenge.

Kind regards,

Tim

developit commented 5 years ago

The big note at the top of that document has what's likely a better answer than I can give: eval() isn't an instant performance bailout, and the way it's being used here would mostly impact initial execution. AFAIK it would not prevent hot code from being JIT'ed.