News for hackers. Stuff that matters.
Re:What makes WebAssembly fast? by aphextron on Wednesday March 01, 2017 @12:56AM (#13761560)
My excitement for WASM has nothing to do with speed or efficiency of the runtime. It's all about finally having a universal compile target for the web. We're finally going to be able to develop web apps in a proper language of our own choosing, without needing hacks like TypeScript.

Hopefully, this will lead to real dedicated IDE tooling and standardized libraries for the web along the lines of what's available in iOS and Android native development.

Re:What makes WebAssembly fast? by themihai on Wednesday March 01, 2017 @01:09AM (#13761623)
That's what I find great too, though for some reasons they put too much emphasis on JS-wasm compatibility and less on language support(i.e DOM or GC are considered "unicorn" features). I'm pretty sure 90% of the web developers won't mix js with wasm once they can compile their preferred language to wasm. You will find either js apps or wasm apps. There may be also a very small percent of js apps with wasm modules(i.e for video decoding)
Re:What makes WebAssembly fast? by vonklaus on Wednesday March 01, 2017 @03:08AM (#13762161)
They are trying to convert current web devs. JS is the language of the browser and essentially the web, so most developers working in webdev primarily work w/ js.
Re:What makes WebAssembly fast? by gjjrfcbugxbhf on Wednesday March 01, 2017 @03:21AM (#13762216)
Actually many of us use es6 with a compiler to turn into some dialect of js that runs in browsers. We will hardly notice if our code starts getting compiled to wasm instead..
Re:What makes WebAssembly fast? by v413 on Wednesday March 01, 2017 @04:14AM (#13762407)
JS will not compile to WASM.
Re:What makes WebAssembly fast? by yumaikas on Wednesday March 01, 2017 @04:55AM (#13762582)
Eh, there isn't any reason that it couldn't at some point in the future. That won't be happening any time soon, but I'd love to see that day, personally.
Re:What makes WebAssembly fast? by rkangel on Wednesday March 01, 2017 @06:17AM (#13762896)
Lack of GC in WASM would make that difficult right now.

But yes, that's the future I'd like to see. Browsers only have a WASM engine, and provide a JS->WASM compiler client-side for backwards compatibility.

Re:What makes WebAssembly fast? by marcosdumay on Wednesday March 01, 2017 @08:41AM (#13763543)
GC is just something you implement on the language runtime.
Re:What makes WebAssembly fast? by dcherman on Wednesday March 01, 2017 @10:47AM (#13764601)
Then you're shipping the entire (or at least large pieces of) language runtime to the client since presumably, you'd need to compile that to WASM as well.
Re:What makes WebAssembly fast? by yumaikas on Thursday March 02, 2017 @04:42PM (#13778507)
Given that runtimes like Lua are comparable in size to a single image, and/or could be cached in web browsers, I don't think that will much of a problem. And the more that WebAssembly adds, the smaller that will get.

Obviously if we're trying to run a full JVM or CLR in WebAssembly, that will cause problems, but C# and F# both have compile-to-js targets that would likely just get faster.

Re:What makes WebAssembly fast? by gjjrfcbugxbhf on Wednesday March 01, 2017 @01:40PM (#13766794)
Something that never really worked was cached versions of jquery (and similar) from cdn. One reason is that browsers didn't give them any particular precedence. The other was that jquery was moving quite fast compared to devs using it so as an end user i nearly never benefited from the caching. I wonder if this might work better for language run times. Maybe browsers could be provided with some manifest saying 'this site needs python 3+' or 'this site needs python 3-3.5' so that end users end up with less runtimes cached.
Re:What makes WebAssembly fast? by marcosdumay on Wednesday March 01, 2017 @01:20PM (#13766592)
You can probably fit the runtime in a 10th of the size of JQuery.

You'll need most of a runtime anyway, since it provides much more than GC.

Re:What makes WebAssembly fast? by themihai on Wednesday March 01, 2017 @10:06AM (#13764190)
The JS devs don't really need wasm. JS works just fine in browser. I find the use cases mentioned (js app + high performance wasm modules) limited to a very small niche. WASM is supposed to be a target language. Are they trying to convert current web devs to C++/rust devs? It doesn't make any sense to me. If wasm was designed just to help JS to do more then it is doomed to fail.
Re:What makes WebAssembly fast? by aphextron on Wednesday March 01, 2017 @10:38AM (#13764501)
>JS works just fine in browser.

Sure it does. And the myriad of languages that pop up to support WASM will work infinitely better. ES6 was a huge step forward, but it's still a long way from a real language like C#.

I suspect Javascript development will always be a thing, but that front end development will fracture into multiple different languages and runtimes as full WASM support comes online.

Re:What makes WebAssembly fast? by joshuahutt on Wednesday March 01, 2017 @11:07AM (#13764822)
> a real language like C#

While I can agree that C# has tons of language features that make it more powerful than JavaScript, I take issue with the idea that those features are the defining characteristic of a "real" language. I think there are many reasons to choose C# over JS, but there are also a non-trivial of reasons to make the opposite choice.

https://blog.codinghorror.com/the-principle-of-least-power/

Re:What makes WebAssembly fast? by charlieflowers on Wednesday March 01, 2017 @02:07AM (#13761872)
True. I agree with it all.

However, by then, TypeScript might be so darn good that people choose to keep going with it!

It really does have a better type system than C# in a lot of ways.

Re:What makes WebAssembly fast? by throwaway010317 on Wednesday March 01, 2017 @04:17AM (#13762421)
Could you please elaborate on how TypeScript's type system is better than C#?
Re:What makes WebAssembly fast? by nothrabannosir on Wednesday March 01, 2017 @04:34AM (#13762505)
I disagree with OP, but two interesting corollaries of TS type semantics are its strong type inference and structural typing:

Const x = [{x: 3, y: "hi"}, {x: 9, y: "bye"}];

Automatically gets you x: "Array of {x : number, y: string }". And if you declare the same type somewhere else, as long as they're "structurally equivalent" (i.e. same x and y types) you can actually use them interchangeably. You can't do that e.g. with c#, where one class will never be exchangeable with an unrelated class , no matter how similar the definitions.

This lets you do some funny stuff like"subset type detection ": https://gist.github.com/hraban/66c1778cdd31868034b12db93fcce...

All in all, it's more of an oddity than an actual strength, if you ask me. It's necessary to emulate JS semantics, but I wouldn't consider it an advantage in a new language.

Re:What makes WebAssembly fast? by aphextron on Wednesday March 01, 2017 @10:43AM (#13764548)
> You can't do that e.g. with c#, where one class will never be exchangeable with an unrelated class , no matter how similar the definitions.

Agreed. Duck typing is a killer feature. I can't say how many time's I've rolled a new class for no reason other than data structuring, which would have been far preferable as something just defined inline.

Re:What makes WebAssembly fast? by charlieflowers on Wednesday March 01, 2017 @10:41AM (#13764534)
Mostly, for me, it comes down to union types, intersection types, the ability to disallow implicit nulls (meaning null must be declared as a valid value at the type level, and therefore cannot creep in unexpectedly), string literal types, discriminated unions (most of the good stuff from algebraic data types), and index types.

All demonstrated here: https://www.typescriptlang.org/docs/handbook/advanced-types....

The result is a very nice, expressive way to state your types and get maximal benefit from the type checker.

Re:What makes WebAssembly fast? by tonyedgecombe on Wednesday March 01, 2017 @03:52AM (#13762317)
It could be another target for TypeScript though.
Re:What makes WebAssembly fast? by v413 on Wednesday March 01, 2017 @04:18AM (#13762428)
Typescript is designed to be compiled to JS. WASM is designed for staticly compiled languages. Even if there is GC and DOM access through WASM, Typescript will be better off to run for the natively JIT optimized JS path.
Re:What makes WebAssembly fast? by oneweekwonder on Wednesday March 01, 2017 @06:07AM (#13762861)
Really?

Anders Hejlsberg is in charge of TypeScript and a apt compiler architect with a proven track record(turbo pascal, delphi, .net/C#).

Re:What makes WebAssembly fast? by readittwice on Wednesday March 01, 2017 @10:52AM (#13764641)
Sure, Anders is great but this not so easy. Basically you would have to re-implement all the features and optimizations of current JS-Engines. In WASM you are restricted to the given (statically-typed) opcodes, while a JS-JIT has more knowledge about program semantics and can thus apply optimizations more easily. In addition the JIT can also make use of hand-written assembly if it is needed for best performance.

I think JRuby does a similar thing for Ruby and Java Bytecode. TruffleRuby shows that it is possible to be faster, they do not compile to bytecode and use their own compiler.

Re:What makes WebAssembly fast? by RussianCow on Friday March 03, 2017 @12:39PM (#13784518)
Sure, but all else being equal, a statically typed language will always be faster than a dynamically typed one, because you can do way more optimization at compile-time rather than run-time. So you're right in that JS is pretty darn fast, but it probably wouldn't take that much effort to surpass JS performance with a custom TypeScript -> WASM compiler.
Re:What makes WebAssembly fast? by readittwice on Tuesday March 07, 2017 @04:41AM (#13809294)
Sure, but AFAIK TypeScript is not generally fully statically typed. You could just rename a .js file to .ts and call that TypeScript. Please correct me if I am wrong.

There are some dynamically typed languages like Python or Dart that allow (or are in the process to allow) type annotations. But all these languages I know about claim that type annotations do not help performance. I guess you could define a fully statically typed subset of TypeScript that allows you to compile it to fast WebAssembly bytecode. But that would probably also mean to change some semantics: see int vs double for numbers in JavaScript.

Re:What makes WebAssembly fast? by RussianCow on Tuesday March 07, 2017 @11:24AM (#13811635)
The only reason type annotations in those languages don't increase performance is that they compile down to JS, which is dynamically typed, so all static type information is lost. But you're right, you would either have to annotate everything with types, or re-implement the JS runtime in WASM in order to gain any benefit from it. The most feasible option would be to target a fully-typed subset of TS, which may or may not be practical.
Re:What makes WebAssembly fast? by readittwice on Thursday March 09, 2017 @06:35PM (#13834903)
I am not sure what you mean? Both Python (PyPy) and Dart have a JIT (yes, you can also compile Dart to JS), so they don't lose type information in those VMs. See what the PyPy-Devs have to say about type annotations and performance (they have a faq entry for that!): http://doc.pypy.org/en/latest/faq.html#would-type-annotation... And here is what the Dart devs have to say: https://www.dartlang.org/faq#q-but-dont-you-need-sound-typin...

Your claim was "it probably wouldn't take that much effort to surpass JS performance with a custom TypeScript -> WASM compiler"

I guess you basically have two options:

1) Implement a JS-Engine on top of WASM. Which is a lot of work. But what could you do to get better performance than current JS-Engines? Every optimization you can implement on top of WASM, you can also implement for native JS-Engines. Quite the contrary it is even harder, since you are an abstraction layer higher and can only make use of WASM opcodes.

2) Define a fully-statically typed subset of Dart and compile to WASM. You could sure do that, but don't forget about e.g. the ubiquitous number type in JS/TS. You may have to use double (almost) everywhere if you want to match semantics of JS. How many non-trivial TypeScript programs could such a subset run successfully? I assume not a lot.

I don't see how you could write a TypeScript to WASM compiler without much effort. Care to explain?

Re:What makes WebAssembly fast? by KurtMueller on Wednesday March 01, 2017 @10:08AM (#13764202)
F# has an even better type system :)
Re:What makes WebAssembly fast? by zurn on Wednesday March 01, 2017 @07:55AM (#13763287)
JS provided that already without WebAssembly, no?
Re:What makes WebAssembly fast? by mkawia on Wednesday March 01, 2017 @08:16AM (#13763407)
I don't understand why the downvotes , JS is one of the most target languages. Elm,GHJS(Haskell),Purescript,Clojurescript and supersets like Typescript which come with their own toolchains.
Re:What makes WebAssembly fast? by fulafel on Wednesday March 01, 2017 @11:56AM (#13765488)
Also Javascript itself is frequently compiled down to an older version of Javascript.
Re:What makes WebAssembly fast? by bluejekyll on Wednesday March 01, 2017 @09:37AM (#13763901)
Asm.js was exactly what your talking about.

You can think of webassembly more like a common standard akin to the JVM specification. Anyone can implement the spec.

It's a formal definition of what people are doing with JS.

Re:What makes WebAssembly fast? by scriptproof on Wednesday March 01, 2017 @03:04AM (#13762143)
You can write wasm. It is the official shortcut (not an acronym). Source: http://webassembly.org/
Re:What makes WebAssembly fast? by unwind on Wednesday March 01, 2017 @05:46AM (#13762788)
Re:What makes WebAssembly fast? by jlebrech on Wednesday March 01, 2017 @07:48AM (#13763250)
Leading to real IDEs, real languages, real libraries.

downsides will be some proprietary solutions will crop up.

Re:What makes WebAssembly fast? by vikas0380 on Wednesday March 01, 2017 @12:23PM (#13765850)
There is no harm in that
Re:What makes WebAssembly fast? by amelius on Wednesday March 01, 2017 @04:27AM (#13762467)
Is it possible to run an efficient garbage-collected runtime system on top of WASM? And how about a multithreaded one?