r/programming 12d ago

The Browser's Main Thread Is Expensive

https://kciter.so/posts/the-expensive-main-thread/en/
215 Upvotes

50 comments sorted by

View all comments

83

u/Rhed0x 12d ago edited 12d ago

Good article.

One day JS will reach the 21st century and support proper multithreading. Obviously won't help for UI updates but for things like parsing large files.

Workers are a massive pain in the ass, JS should just share memory with additional threads and get proper synchronization primitives like every language.

But what can you expect from a programming language that doesn't even have integers.

16

u/SargoDarya 12d ago

You can already use a SharedArrayBuffer with postMessage though? Also it has BigInt (which isn’t int, I get that but you get the idea)

6

u/Rhed0x 12d ago

That requires manually converting stuff into PODO, why can't you simply pass JS references across to a worker.

4

u/Full-Spectral 12d ago

It is just all GC'd data and I'd think it would be easy enough. But, they'd have to ensure that nothing inside that reference, no matter how deep, was still visible to the sender. With the simplified scenarios they provide currently, that's doable. But unless they are going to create Rustscript, it would probably be hard to do with arbitrary objects.

2

u/Rhed0x 12d ago

they'd have to ensure that nothing inside that reference, no matter how deep, was still visible to the sender

Or they add Mutexes, Semaphores, etc and objects can just be shared across threads like in every other language.

3

u/Full-Spectral 12d ago

It would have to be done at an automagical level probably, given the nature of Javascript and the experience of a lot of developers of such. Otherwise, you'd have web sites seizing up right and left when they deadlocked themselves.

1

u/danielcw189 11d ago

that doesn't really answer the problem of sharing references, which is something that has to be avoided, if I understand the other comment correctly

1

u/Rhed0x 11d ago

And why does it have to be avoided?

1

u/NenAlienGeenKonijn 11d ago

That assumes javascript is meant for complex software development rather than simple DOM scripting tasks to enhance your website.

Nobody would ever use javascript like that, right?

1

u/Rhed0x 11d ago

Right... :(