Live data from Hacker News

When to use web workers

dassur.ma

61–70 of 110 posts

Re: When to use web workers

#61
post #55

Earlier quoted context omitted.

Pro tip: if you ask a user to install a different browser, they're just as likely to use a different site instead.

they're just as likely to use a different site instead. just as likely, or more likely?

Depends on the site. In some cases, less likely. E.g. at this point in time, Facebook or YouTube or even Slack could make a browser change demand with little to no consequences.

Re: When to use web workers

#62
post #17

Earlier quoted context omitted.

What percentage of your users use Safari? If it isn't impactful to your business, you could ask them to use Firefox or Chrome. I realize we need more browser diversity and not less, but at the same time we should encourage all participants to keep up so that the burden doesn't fall on smaller players.

Pro tip: if you ask a user to install a different browser, they're just as likely to use a different site instead.

Depends on the user. My GF for some reason uses FF, Edge and Chrome at the same time, most of the time (she's not in/into tech).

So if someone asked her, she would just switched the windows.

Re: When to use web workers

#63

Earlier quoted context omitted.

Static _is_ better for a good bunch of performance metrics. But what about interactive content like https://proxx.app ? The article is mostly aimed at use-cases where some sort of logic in JavaScript is required.

Yes @dassurma. But web workers are not everything. Your own blog post does not score 100 : https://developers.google.com/speed/pagespeed/insights/?url=... And those issues are not necessarily addressed with web workers. Good basic static design matters too.

They scored a 96. There is exactly one issue, and it’s esoteric in my opinion.

Re: When to use web workers

#64
post #17

Earlier quoted context omitted.

What percentage of your users use Safari? If it isn't impactful to your business, you could ask them to use Firefox or Chrome. I realize we need more browser diversity and not less, but at the same time we should encourage all participants to keep up so that the burden doesn't fall on smaller players.

Pro tip: if you ask a user to install a different browser, they're just as likely to use a different site instead.

Depends on the market; I don't think it's that common in enterprise, for instance, to have Windows 10-using orgs with virtually no use of the default (Edge) browser, but large numbers of users with both IE and Chrome because of (legacy and modern) app demands.

Re: When to use web workers

#65
post #43

Earlier quoted context omitted.

People have been taking plenty advantage, they are an indispensable tool to turn all of these CPU bugs or DRAM attacks into working browser exploits. Also those bitcoin miners of course. Maybe if no one else is taking advantage it is time to simply throw them out.

“I don’t use it, therefore no one else uses it” As an example, emscripten uses WebWorkers and SharedArrayBuffers to implement multithreading (unfortunately or not, Chrome is the only browser that supports SharedArrayBuffer, others have disabled it).

I suggest you look up why they disabled it. And that is still not an application of WebWorkers!

It would be much more helpful to the cause if you could point to some actually used app out there principally relying on WebWorkers. Until then, it's been a lot of pain, zero gain.

Re: When to use web workers

#66
post #48

Earlier quoted context omitted.

IndexedDB is shared between workers and main thread, in case that helps.

Indeed, and it is something I'm looking at. But at the moment my database is really native Clojure data structures, which has fantastic advantages. I would need to start storing them in a "traditional" database, introducing additional layers, serialization, overhead and bugs.

> I would need to start storing them in a "traditional" database, introducing additional layers, serialization, overhead and bugs.

If the app state is stored in a single atom, I would use localForage[1] (available as a cljsjs package[2]) to keep it in sync between web workers and the main thread. It would also make the app accessible offline.

[1] https://github.com/localForage/localForage

[2] https://clojars.org/cljsjs/localforage

Re: When to use web workers

#67
post #53

Hey @dassurma, can you explain your task scheduling function? As far as I can tell it schedules a micro task, and there is no meaningful difference between that and other microtask scheduling systems: https://codepen.io/ruphin/pen/qzbgYr?editors=0012

All your logs are executed immediately. .then() takes a callback function!! FYI: AsyncTask and MicroTask are equivalent, and so are my task() function and your OnMessageTask

Ah, I messed up in my haste to experiment :)

I expaned my tests a bit and your version does indeed queue a task and not a micro task. I did find it to be somewhat less reliable than setTimeout, is there a particular reason why you used this scheme instead of a setTimeout based solution to queue tasks? Why did you choose this method in particular to queue tasks?

Also, AsyncTask and MicroTask are not fully equivalent. MicroTask is equivalent to a bare `await 0;`, but because AsyncTask wraps that in another async function it will queue a second micro task when the first one resolves, and resolve the promise when the second micro task resolves :)

Re: When to use web workers

#68
post #67

Earlier quoted context omitted.

All your logs are executed immediately. .then() takes a callback function!! FYI: AsyncTask and MicroTask are equivalent, and so are my task() function and your OnMessageTask

Ah, I messed up in my haste to experiment :) I expaned my tests a bit and your version does indeed queue a task and not a micro task. I did find it to be somewhat less reliable than setTimeout, is there a particular reason why you used this scheme instead of a setTimeout based solution to queue tasks? Why did you choose this method in particular to queue tasks? Also, AsyncTask and MicroTask are not fully equivalent.…

Why do you think it's less reliable? setTimeout gets clamped by the browser to a minimum of 4ms, so you waste a lot of time when all you want is a task boundary.

Re: When to use web workers

#69
post #43

Earlier quoted context omitted.

People have been taking plenty advantage, they are an indispensable tool to turn all of these CPU bugs or DRAM attacks into working browser exploits. Also those bitcoin miners of course. Maybe if no one else is taking advantage it is time to simply throw them out.

“I don’t use it, therefore no one else uses it” As an example, emscripten uses WebWorkers and SharedArrayBuffers to implement multithreading (unfortunately or not, Chrome is the only browser that supports SharedArrayBuffer, others have disabled it).

This whole thread was quite overwhelming. I was starting to feel, can we just have a normal CPU machine and some C in it? That is horrible too, but in a way I can understand. And sure enough, emscripten gets mentioned. :-D

Re: When to use web workers

#70
post #5

What is the use-case? Why is static not better? What are the edges?

Static _is_ better for a good bunch of performance metrics. But what about interactive content like https://proxx.app ? The article is mostly aimed at use-cases where some sort of logic in JavaScript is required.

Heavily interactive content in the browser is an edge case for vast majority of mobile users.

Outside of that edge case the best solution is usually to use JS to sprinkle functionality not doing heavy lifting.

Post reply on HN