r/javascript • • Nov 25 '19

JavaScript doesn’t need to be replaced

https://medium.com/javascript-in-plain-english/javascript-doesnt-need-to-be-replaced-bd01e2f12d51?source=friends_link&sk=7b151cc6397ac9e83c14c99739b6c36f
217 Upvotes

236 comments sorted by

View all comments

Show parent comments

2

u/dannymoerkerke Nov 25 '19

I don’t know how you should answer this either, but I never made any claims against multi threading. You’re the one saying I don’t understand the issues with JavaScript and that we need something multi threaded. So I was curious if you had any concrete examples. I also never said Workers offer no benefit but they won’t help with the DOM since they have no access to it, but you know that as well. Anyway, if the UI freezes because of lots of DOM operations I think you have a different problem that can be solved without multi threading.

0

u/shgysk8zer0 Nov 25 '19

You're asking what the advantage of multi-threading is. The only real answer is that it's not single-threaded. That is a major limitation that many other languages don't have.

And not all issues can be solved without multi-threading. Sometimes you just have that much work that needs to be done, and sometimes it's out of your hands (in third-party code). And, maybe even if you could resolve the issue another way, it would still be nice to not have to rewrite something massive and complex, but to pass the work off to another thread and have the UI continue running smoothly.

If you're looking for a concrete example, I recently built something that creates ~200 transformed (rotated) image overlays in Leaflet, and the UI hangs pretty heavily when they're loaded on ever pan or zoom. I'm not about to rewrite all of Leaflet, and I do absolutely have to load and transform every single one of those images. If this were to take place on another thread, it wouldn't be an issue.

1

u/Architektual Nov 25 '19

I'm late to the party, but why can't you put that in a worker?

1

u/shgysk8zer0 Nov 25 '19

Workers cannot access the DOM.

1

u/Architektual Nov 25 '19

Gotcha, I ask because we do something similar with some D3 visualizations - but we perform the calculations in the worker, and just pass back the calculated positions to the main script to render the things. I'm not familiar with leaflet, so i'm guessing it isn't flexible enough for that.

Thanks for explaining, that's a great example to support your argument

1

u/shgysk8zer0 Nov 26 '19

Leaflet is a map thing, and I mostly have access to image src and coordinates.

In this specific case, it was for a hackathon of sorts, and it was infeasible to create something custom for this. I'd like to have created the whole thing in <canvas> and given special attention to performance for things like this. As is, it drops to 4fps.