Live data from Hacker News

Web Workers API

developer.mozilla.org

41–47 of 47 posts

Re: Web Workers API

#41

Web Workers makes it possible to run a script operation in a background thread separate from the main execution thread of a web application. The advantage of this is that laborious processing can be performed in a separate thread, allowing the main (usually the UI) thread to run without being blocked/slowed down.

That can be a great feature in some circumstances, but it also seems like it can undo much of the efficiency improvement browsers have accomplished by throttling and sleeping less used tabs. Do browsers implement any kind of leashing in terms of how much resources any particular site’s workers can use, frequency of running, length of runs, etc?

Re: Web Workers API

#42
post #21
post #15

is web worker really good for some costly processes? would it really be useful for a dashboard with sample instant data flow?

We used web workers to shift a lot of processing off of the main thread. They helped in keeping the UI feeling responsive and less laggy.

What kind of processing do you mean? Unless you're developing a game or a media player, I can't think of a good example where processing might delay the UI.

Re: Web Workers API

#43
post #25

The fact that creating a worker requires you to pass a module (file) name makes them extremely unergonomic to use. This is clearly visible in the lack of any library ecosystem around them. We don't have any highly used threadpool or executor libraries using workers. Everyone seems to be manually setting up a worker and setting up the job scheduling logic from scratch. All the boilerplate and restrictions really restr…

I agree it is weird, but there is a Blob API so you don't strictly have to use a filename.

https://stackoverflow.com/a/6454685/265521

And do you have a reference for the caching issue? I tried to Google it but all I found was people saying that web workers were cached too much, not that they aren't cached at all.

Re: Web Workers API

#45

Earlier quoted context omitted.

I should check what's the status with Atomics.wait on Chrome, currently it seems to work fine under both Node and Deno. I'll test out the regex thing in the following days as I need it for that exact use case, I just assumed killing the web worker would... work, hopefully that's the case otherwise I'm back to square 0 :D --- Edit: MDN says: "The terminate() method of the Worker interface immediately terminates the Wo…

Worker.terminate() aborts the currently running script evaluation, see https://html.spec.whatwg.org/multipage/workers.html#dom-work... → https://html.spec.whatwg.org/multipage/workers.html#terminat... → https://html.spec.whatwg.org/multipage/webappapis.html#abort... , but that’s a fairly fuzzy definition, and it’s not generally reasonable to expect that to interrupt a currently executing piece of native code, because…

At least in Chrome it works as advertised: https://twitter.com/fabiospampinato/status/14683093104804741...

Re: Web Workers API

#46

Earlier quoted context omitted.

Worker.terminate() aborts the currently running script evaluation, see https://html.spec.whatwg.org/multipage/workers.html#dom-work... → https://html.spec.whatwg.org/multipage/workers.html#terminat... → https://html.spec.whatwg.org/multipage/webappapis.html#abort... , but that’s a fairly fuzzy definition, and it’s not generally reasonable to expect that to interrupt a currently executing piece of native code, because…

At least in Chrome it works as advertised: https://twitter.com/fabiospampinato/status/14683093104804741...

Syntax errors there, t.co mangulation of e.data.

Seems to work in Chromium, though it looks like it might be taking a second or two to actually terminate it. It’s a bit harder to tell if it works in Firefox, because Firefox kills the regular expression within five seconds with the error from RegExpBuiltinExec “too much recursion”, but I think it is, and probably faster than Chromium, though it’s hard to be certain when just doing the lazy check of CPU usage at one second granularity.

Re: Web Workers API

#47

Earlier quoted context omitted.

At least in Chrome it works as advertised: https://twitter.com/fabiospampinato/status/14683093104804741...

Syntax errors there, t.co mangulation of e.data. Seems to work in Chromium, though it looks like it might be taking a second or two to actually terminate it. It’s a bit harder to tell if it works in Firefox, because Firefox kills the regular expression within five seconds with the error from RegExpBuiltinExec “too much recursion”, but I think it is, and probably faster than Chromium, though it’s hard to be certain wh…

> Syntax errors there, t.co mangulation of e.data.

Interesting! They must have changed something because when I published that the code looked alright, albeit with some stuff linkified.

Post reply on HN