Live data from Hacker News

Concurrent JavaScript: It can work

webkit.org

101–110 of 189 posts

Re: Concurrent JavaScript: It can work

#101
post #81

Earlier quoted context omitted.

When told that multi-threaded access is hard and messy, "X program uses threads and it's not a mess" is not an argument -- for one because nobody said X program is a mess. Threads being messy is not a transitive property. Nobody doing threads ever said that they are not messy or that multi-thread access and locking et al are easy.

I do threads and I just said that they are not messy.

Well, nobody sane then if I'm allowed the Scotsman! People also defend all kinds of dangerous constructs or practices blaming other programmers for not being good enough to use them even though statistically even the best programmers suffer from problems derived from them (e.g. buffer overflows, or in the case of threads race conditions, starvation, etc.).

And since we're particularly talking about adding threads to Javascript, here's the opinion of the creator of Javascript itself on threads:

  You must be this tall to hack on threaded systems, and that 
  means most programmers should run away crying. But they 
  don’t. Instead, as with most other sharp tools, the 
  temptation is to show how big one is by picking up the 
  nearest ST code and jamming it into a MT embedding, or 
  tempting race-condition fate otherwise. Occasionally the 
  results are infamous, but too often, with only virtual 
  fingers and limbs lost, no one learns.

  Threads violate abstractions six ways to Sunday. Mainly by 
  creating race conditions, deadlock hazards, and pessimistic 
  locking overhead. And still they don’t scale up to handle 
  the megacore teraflop future.

  https://brendaneich.com/2007/02/threads-suck/
Also, are you the author of TFA? That sure speaks to your skills, but that doesn't mean standard definitions (e.g. on concurrency) or traditional consensus (e.g. on threads being messy) don't apply.

Re: Concurrent JavaScript: It can work

#102

Earlier quoted context omitted.

I mean, you could say the same thing about assembly language programs. "Either static or dynamic typing is needed to prevent large programs from becoming a twisted mess" is a pretty uncontroversial statement today, despite the fact that there were some very high quality large assembly language programs written back in the DOS days. Besides, WebKit doesn't do fine-grained parallelism on the level of parallel styling o…

WebKit does a lot of fine grained parallelism. I think you’re way too casually dismissing how awesome shared memory is.

With all due respect, no, it doesn't do fine grained parallelism in the areas I described. Do I think it would be impossible to add parallel styling or layout to WebKit? No. Do I think it would be difficult? Absolutely, primarily because of the difficulty of finding all the concurrency hazards in existing objects and making them thread-safe. It would be easier with a type system that automatically checks for and highlights such problems. Such a system is precisely what I'm advocating.

And I'm not saying not to use shared memory. I'm saying that shared memory should be controlled by some sort of static or dynamic type system that enforces proper locking or immutability as the case may be. Such a system is hardly a far-fetched idea, as we're successfully using one right now in the style system of nightly Firefox.

Re: Concurrent JavaScript: It can work

#103
post #47

Earlier quoted context omitted.

WebKit needs tons of extra effort to keep it from being a twisted mess precisely because it uses threads.

Any well written software requires effort to properly design and maintain. What’s the argument here? “Don’t give them shotguns, they might shoot themselves”?

Don't load the shotguns, turn off the safety, point it at their foot and tell them “please be careful”.

Re: Concurrent JavaScript: It can work

#104
post #90
post #36

Earlier quoted context omitted.

Is there any limitation or reason for not implementing WASM on nodejs?

What's the point? Why not write your server directly in say Python or Java then? I thought WASM is meant to get around the restriction that the browser only understands JS right now.

> why not use X

Because X doesn't run in a browser

Re: Concurrent JavaScript: It can work

#105
post #10

Of course the language can be made to support it. Given the way Javascript is used, the question is whether supporting it will create a big mess. They have some good ideas. One is that variables can be marked as restricted to one thread. That should be the default. Other languages could benefit from that feature. Python, for example. If you want to get rid of the Global Interpreter Lock, knowing which variables can't…

I think it would be weird if objects were thread-restricted by default. Concurrency is most fun when it's easy for a thread to access an object it wants.

Yeah, if by "fun" you mean "catastrophic"

Re: Concurrent JavaScript: It can work

#106
post #104
post #90

Earlier quoted context omitted.

What's the point? Why not write your server directly in say Python or Java then? I thought WASM is meant to get around the restriction that the browser only understands JS right now.

> why not use X Because X doesn't run in a browser

Do you need to run your server in a browser?

Re: Concurrent JavaScript: It can work

#107

Earlier quoted context omitted.

WebKit does a lot of fine grained parallelism. I think you’re way too casually dismissing how awesome shared memory is.

With all due respect, no, it doesn't do fine grained parallelism in the areas I described. Do I think it would be impossible to add parallel styling or layout to WebKit? No. Do I think it would be difficult? Absolutely, primarily because of the difficulty of finding all the concurrency hazards in existing objects and making them thread-safe. It would be easier with a type system that automatically checks for and high…

It would have been a shame if the OSes on which Firefox runs had similarly limited access to shared memory to one particular "safe" style in the spirit of paternalistic caution.

Would Rust/Servo have been possible without access to the raw rope?

Re: Concurrent JavaScript: It can work

#108

Earlier quoted context omitted.

Events and asynchronous operations are sufficient enough for a concurrency library to be built on top of JS with minimal changes. I wouldn't consider what JS has now a reasonable concurrency model but the asynchronous event handling could serve as a starting point for a source of events that run on multiple threads.

That was the state-of-the-art in OS concurrency in the early nineties. Sometimes, you would have to reboot your computer because some app forgot to yield the event loop. It's not as bad if you have to restart your app because some task forgot to yield the event loop, but it's still bad. Threads solve this problem comprehensively because threads get to make progress regardless of whether or not other threads are in a…

> That was the state-of-the-art in OS concurrency in the early nineties.

Many systems had pre-emptive multitasking in seventies and eighties.

I think Amiga was the first implementation for consumers. Released in 1985. https://en.wikipedia.org/wiki/Amiga_1000

Re: Concurrent JavaScript: It can work

#109

Earlier quoted context omitted.

With all due respect, no, it doesn't do fine grained parallelism in the areas I described. Do I think it would be impossible to add parallel styling or layout to WebKit? No. Do I think it would be difficult? Absolutely, primarily because of the difficulty of finding all the concurrency hazards in existing objects and making them thread-safe. It would be easier with a type system that automatically checks for and high…

It would have been a shame if the OSes on which Firefox runs had similarly limited access to shared memory to one particular "safe" style in the spirit of paternalistic caution. Would Rust/Servo have been possible without access to the raw rope?

Rust is a relatively hands-off style of thread-safety: it protects against data races but doesn't try to get things like deadlock freedom that other more restrictive systems require. The benefits apply when using locks, or message passing or even raw atomics (and similarly to higher level libraries like data parallelism in rayon).

However, Rust is also explicitly designed to allow access to the "raw rope" when abstractions don't cut it (or when building the abstractions): that is what `unsafe` allows.

Re: Concurrent JavaScript: It can work

#110
post #104

Earlier quoted context omitted.

> why not use X Because X doesn't run in a browser

Do you need to run your server in a browser?

No, but it's very nice to be able to share code for things like view rendering or form validation between the server and client without jumping through hoops.
Post reply on HN