How Converting A C++ Game to JavaScript Gave Us WebAssembly (ieee.org) 139
Slashdot reader Beeftopia shares "a detailed history of WebAssembly...from one of the developers." IEEE Spectrum reports that "Like a lot of stories about tech innovation, this one started with video games."
[Mozilla's Alon Zakai] wanted to take a game he had helped write in C++ and convert it to JavaScript code that would run well on the Web. This was in 2010, and back then, converting C++ to JavaScript was unthinkable... so he started working to adapt an open-source tool that could translate C++ code into JavaScript automatically. He called his project Emscripten... we were able to formalize the permitted JavaScript patterns, to make the contract between Emscripten and the browser completely clear. We named the resulting subset of JavaScript asm.js... I would optimize the JavaScript engine in Firefox to run the resulting code even faster...
This brings us to the present... Emscripten can take code written in C++ and convert it directly into WebAssembly. And there will be ways in time to run other languages as well, including Rust, Lua, Python, Java, and C#. With WebAssembly, multimillion-line code bases can now load in a few seconds and then run at 80 percent of the speed of native programs. And both load time and execution speed are expected to improve as the browser engines that run the code are made better.
They'd started with a C++ game because "If we could make games run well on the Web, other computationally intensive applications would soon follow."
The article -- by Mozilla software engineer Luke Wagner -- remembers that the name Emscripten was a "a mash-up of 'script' from JavaScript and 'embiggen' from the TV show The Simpsons."
This brings us to the present... Emscripten can take code written in C++ and convert it directly into WebAssembly. And there will be ways in time to run other languages as well, including Rust, Lua, Python, Java, and C#. With WebAssembly, multimillion-line code bases can now load in a few seconds and then run at 80 percent of the speed of native programs. And both load time and execution speed are expected to improve as the browser engines that run the code are made better.
They'd started with a C++ game because "If we could make games run well on the Web, other computationally intensive applications would soon follow."
The article -- by Mozilla software engineer Luke Wagner -- remembers that the name Emscripten was a "a mash-up of 'script' from JavaScript and 'embiggen' from the TV show The Simpsons."
I see the problem. (Score:2, Insightful)
With WebAssembly, multimillion-line code bases can now load in a few seconds and then run at 80 percent of the speed of native programs.
You appear to believe that is a good thing, in a web browser.
Re:I see the problem. (Score:5, Insightful)
It is a good thing, for a handful of uses, which you might run into once a year. Unfortunately the other 99.99999% of the time it'll be used to create monstrosities which every website will shove down your throat.
Re: (Score:2)
The extremely gullible - ie the target most marketeers would give their eye-teeth for
Re: (Score:2)
The extremely gullible - ie the target most marketeers would give their eye-teeth for
That doesn't make any sense.
People who want to play a game that happens to be written for a browser play games in a broswer. It's a portable platform for better or worse which provides graphics, sound and keyboard input.
i.e. it provides far more than the minimum needed for videogames.
And some people write games for it just because the can and those ones tend to be pretty good.
Re: (Score:2)
If only computer languages could be used for something other than games. Oh, wait, they can.
The fact that this makes it possible to use languages other than Javascript in the browser should be a cause for rejoicing.
Sounds like a dumb ass (Score:5, Insightful)
I don't like C++ for various reasons, but the only language in a good 40 years of programming I've learned to hate is Javascript.
Re: (Score:2)
He probably talked about the language itself, not the way it is used.
JS is used for more than just webpages, even if it is, by far, its most common use. And ads and tracking are not only JS. On Android, it's Java, on iOS, it is Objective C or Swift.
Re: (Score:1)
You forgot to yell "Get off my lawn!" while waving your cane.
Re:Sounds like a dumb ass (Score:5, Funny)
Real languages do pointer arithmetic (Score:2)
Until WebAssembly can do that it is rubbish.
Re: (Score:1)
You can take code with pointers and compile it to WebAssembly
https://stackoverflow.com/ques... [stackoverflow.com]
Now you may start shouting "All of this is ungodly! All of you are impure!" upon reading this and chant the operator precedence mantra from The Bible [amazon.com] until you calm down and you'd be totally justified in doing so. Still it works.
Re: (Score:2)
Pointer arithmetic is adding numbers to pointers. It is why
int x;...
myOutput("The Answer is " + x)
produces a core dump (if you are lucky). It is what makes C/++ what it is today.
JavaScript is all about pointers, and also has closures, so that is not the issue. It I the unconstrained arithmetic.
Incidentally, 30 years ago Lisp machines used a Lisp-ish assembler that looked a bit like this.
Re: (Score:1)
But it's so easy with Javascript if you use jQuery.
$('kids').on('myLawn').yell("Get off!")
Re: (Score:1)
argh, come on man, CALLBACKS!
var kids_on_lawn=function(o,c){
if(o.onLawn===true){
c(null,'GET OFF MY LAWN');
}else{ c(null,true); }
};
you can also do it asynchronously to take advantage of modern multi core CPU's
var yell=function(o,c){ alert('get off my lawn '+o.name); if(c){c(null,true);}else{return true;} };
var kids=['andy','jane','tod'];
var operations=[];
kids.forEach(function(name){ operations.push(async.apply(yell,{name:name})); });
async.parallel(operations,function(err,res){}
Re: (Score:2)
10 PRINT "GET OFF MY LAWN!"
20 GOTO 10
stupid lameness filter
Re: (Score:2)
surely
$(""#my street" house[lawn]").on("change", ".kids", function() { yell ("get off my lawn") ) });
(so that's in the area of my street identified, the lawn attribute as part of the house element has an event handler attached that looks for changes to it from items of class "kids" and calls a function to do some yelling. Frankly, its starting to make perl look sane.
and the whole thing has to be placed well away from the lawn, in order to use security measures like content security policy that prevents inli
Re: (Score:2)
But it would yell in a very deep monster voice!
Re: (Score:2)
So what's up next . . . ? Erlang . . . ? There's still probably a pretty big pile of FOTRAN waiting around to be WebAssembled.
Hey, and what about all that IBM 360 mainframe code that's been running since the 60's . . . ? Although, IBM probably has that code wrapped up in some legal shackles, so you can't do anything with it, except run it on a newer mainframe.
Maybe we could start WebAssembling JavaScript code . . . ?
Re: (Score:2)
Erlang man is what all the cool kids use now PYSCHO BITCH [youtube.com]
Re: (Score:2, Interesting)
This "dumb ass" basically did what Google's NaCl engineers couldn't do, and helped find an agreeable migration path for web browsers to alter their existing VMs to support other languages. Thanks to him, contrarian fogeys may finally be able to shut the fuck up about JS in a few years. And I consider that a MAJOR win for everyone's sanity.
Re: (Score:1)
no. javascript is still a piece of shit and the concept of the scriptable browser continues to be a security nightmare. The only thing web 'assembly' does is make the malware/bitcoin miner run faster for the attacker.
Re: (Score:2)
bookmarks? Sure beats wading through the mountains of pointless clickfests modern 'UX' designed sites have brought us.
Reductionist? Nah, the problem is the bloat inherent in needless expansionism. Now we have slow, overwrought versions of applications that were already been-there-done-that in 1995, except now they're on a remote site that can change/disappear tomorrow, is loaded with ads/malware, and we get to pay 'subscription' fees for this wonderful 'convenience.'
Re: (Score:2)
They don't - that is why the need to make the code run 20% slower!
Re:Sounds like a dumb ass (Score:4, Interesting)
Wow, modern /.ers really like to dump on people doing fun projects, never mind completely missing the point of the article. Did you even read TFS before making up your knee-jerk response?
Re: (Score:2)
Unless of course it's the article that positions opinion as fact...eg 99% of the political articles posted here.
Re: Sounds like a dumb ass (Score:2)
People who see the web as documents (Score:5, Informative)
You failed to address the elephant in the room: Javascript is the language of the web browser platform.
I think the idea is that a lot of people who regularly post comments on Slashdot and SoylentNews don't want the web browser to be an application platform. They see the web as documents, not applications. They point out that much is achievable through link navigation, form submission, and CSS, such as a script-free version [pineight.com] of the "Fast Good Cheap" 2-of-3 checkbox demo [fastgood.cheap]. If they wanted an application more sophisticated than that, they would download its source code, compile it, and install it.
Re: (Score:2)
Having an application platform that isn't controlled by a single vendor, has no gatekeeper, and can run on any device --- and actually has a huge number of apps --- is incredibly important. The Web is that.
People who don't want the web browser to be an application platform are welcome to disable Javascript in their browser. I'm happy to leave it on.
Re: People who see the web as documents (Score:2)
Having an application platform that isn't controlled by a single vendor, has no gatekeeper, and can run on any device --- and actually has a huge number of apps --- is incredibly important. The Web is that.
Um, yeah, the WEB is that. The web is not your browser.
Applications run server side and the output displays in your browser. There's absolutely no good reason to be writing the goddamn application to actually execute in your browser.
Re: (Score:2)
There's absolutely no good reason to be writing the goddamn application to actually execute in your browser.
Yes there is. It's much more efficient.
Re: People who see the web as documents (Score:2)
JavaScript.
Efficient.
Pick one.
Re: (Score:2)
JavaScript less runtime-efficient than writing six C++14 apps, one for each platform (Win32, UWP, macOS, X11/Linux, iOS, Android). But it's more programmer time-efficient, and it's more efficient than requiring full page reloads of the web IRC gateway every 15 seconds in case someone in an IRC channel typed a new message.
Re: (Score:1)
Re: (Score:2)
While I agree that there is to much JS horrorr in modern browsers, there are plenty of reasons to have part of the logic as JS in the browser. ... could not agree to implement and adhere to standards.
One is scalability. Keep in mind the 'power of JS' with libraries like jquerry, reactJS etc. come from the fact that browser vendors could not agree on standards. Erm
As soon as you give someone a tool, like a 'nice JS library' he has it easier to 'abuse' the tool than to learn the underlying principles of the d
Re: People who see the web as documents (Score:2)
Alright, I was over generalising; I HAVE done web development, and yes, there are times when (properly done) JS is useful and actually adds value either in terms of user experience or efficiency.
However, I also run NoScript in Firefox because the overwhelming majority of JS code out there adds nothing but bloat and constant tracking. Unfortunately, unlike the sites which I developed, many modern sites end up being unusuable or severely crippled without JavaScript enabled, which is a constant source of ann
Re: (Score:2)
Well,
I'm not a fan of JS in the browser.
I'm actually not a fan of web apps either. I mean, web sites that try to behave like an app/program.
I think this is more a 'how should the web work' question than a JS question.
Re: (Score:2)
Would you rather have a web app or a Mac-only app?
Or if your primary computer is a Mac:
Would you rather have a web app or a Windows-only app?
Re: (Score:2)
I avoid using web apps.
And I don't really develop web apps.
All desktop apps I develop are in Java/Groovy/Scala ... so I don't care.
'Web technology' as in HTML5/CSS etc. makes sense for cross platform mobile development.
I don't want a web site as an app ... the only thing that comes close to it that I'm using is FB.
Re: (Score:2)
If the developer of a particular application has the budget to make it for only one target platform, the dichotomy is true. And the web with client-side script has greater user base reach than any single native desktop platform.
Re: (Score:2)
It's only true if doing a cross-platform release will cost more than doing a web-based app, and I don't see any obvious reason for that to be the case 100% of the time.
Anti-script hardliners believe it to be the case 0% of the time, which I imagine is even less likely to be true than 100%.
Allow me to begin the cost analysis:
A web-based application requires a domain (with renewals per year) and a (free) domain-validated TLS certificate, which are less expensive than a set of organization-validated code signing certificates, one for each platform, and renewals per platform per year. Hosting of an applcation's online component is a wash between web and native.
Re: (Score:2)
Applications run server side and the output displays in your browser. There's absolutely no good reason to be writing the goddamn application to actually execute in your browser.
Running part of an application on the client allows for three things:
Re: (Score:3)
That script free version is ugly and slow, even for a trivial example.
Re: (Score:2)
A patch to its CSS to make it less ugly is welcome.
Re: (Score:1)
Re: (Score:2)
Woosh
Let's ignore software distribution, access rights to your own computer (if this is a school or work PC), phones, tablets, other platforms, etc.
If C++ was all in why don't we see these win32 apps on Linux or MacOSX if it was so easy and portable?
Re: (Score:2)
I couldn't disagree more. Javascript is an excellent language, elegant and simple, and a joy to write code in. Building UIs in HTML and CSS is a bit of a pain, and websites that use excessive javascript where none might be necessary are certainly annoying, but neither of those things are anything to do with the language itself.
It's quite different to C++ obviously, but differences in languages encourage you to think differently about problems, which is normally a good thing. WebAssembly, on the other hand,
Re: (Score:1)
I am beginning a project to port the Linux kernel to webassembly.
No need. JSLinux already runs Linux in the browser [bellard.org]. JSLinux can also run Windows 2000 [bellard.org]
Re: (Score:2)
Re: (Score:3, Funny)
Pottering has stated that systemd’s web browser won’t be ready until mid-2018 at the earliest.
Re: (Score:2)
Great, that way you'd be able to run Linux!
Re: (Score:2)
I think we have a linux running javascript based 'VM' in the browser since over ten years.
Re: (Score:2)
what an achievement
It is. It's ideal for running emulators for projects like the Internet Archive's MS-DOS software library [archive.org] or their console video game collection [archive.org].
Re: (Score:2)
The lack of indication of tone of voice in text makes it unreliable for a reader to distinguish deadpan sarcasm from sincerity.
And this is how JavaScript dies (Score:5, Insightful)
It's only a matter of time before TypeScript skips JavaScript and goes straight to WebAssembly. When Python and Ruby can cleanly target WebAssembly and the DOM, it's game over for JavaScript. What'll happen is quite simple. The people who are decent and kinda like JavaScript will jump to TypeScript. Everyone else will write code in something like Python or Ruby. In fact, I'll say right now that I expect that Facebook will rewrite React and GraphQL in TypeScript or one of those languages within no more than a few years of WebAssembly being supported in all browsers.
Re: (Score:1)
Re: (Score:1)
Re: (Score:2)
I think you're wrong.
pray pray pray pray pray pray
Javescript/Ecmascript (giving it a real name, a spec, and a couple books doesn't make it better) really needs to die.
Re: (Score:2)
How hard can this be? (Score:5, Funny)
JavaScript only has 6 commands:
create_message_box_subscribe_to_my_newsetter()
create_message_box_take_our_survey()
create_message_box_our_cookie_policy()
create_message_box_allow_us_to_send_notifications()
create_message_box_behind_browser_advertisement()
create_message_box_behind_browser_clickbait()
Re: (Score:2)
You forgot
create_message_box_use_your_location()
What could possibly go wrong? (Score:5, Insightful)
* in no particular order of undesirability.
** the same-origin policy helps but is not enough, we can't make a trust decision every time we click on a URL, especially now that browser authors have made it so difficult to even see what a link points to, or even understand whether something is a link in the first place. Also, web developers tend to include large amounts of third-party code that they do not inspect, and if such code comes in binary form even before they minify it, then they won't be able to audit that code even nominally.
*** I'm not adding JavaScript to the list. See? I'm not an old person. I like new things!
Re:What could possibly go wrong? (Score:4, Insightful)
WebAssembly programs have access to exactly the same set of APIs that JS programs do. They just run some things faster. There is no change in security (except slightly more attack surface in the form of the WebAssembly compiler, and even that's minimized since browser WebAssembly implementations reuse existing JS compiler backends).
WebAssembly is no more obfuscated than minified Javascript.
Re: (Score:3)
Re: (Score:2)
Am I alone in thinking that giving CPU-level access to our browser to ad networks, hackers, scammers, governments* from all around the world with no authentication and no accountability whatsoever** is a bad idea?
Nope, you are just one of many people. The bad news is that this outcome was inevitable but the good news is that this isn't the final outcome. After a drawn out tug-of-war, a new incarnation of HTML will come to being and it will have limited scripted CSS events that cannot be abused. Ads as we know them will cease to exist and will instead be replaced by a crediting system which will effectively pay sites for content based on various metrics. Credit can be purchased or earned through various means (e.
Re: (Score:1)
It's easy for an ActiveX component to crash almost any host, simply access a NULL pointer from your code. Doing this from a Javascript/asmjs/WASM program is several orders of magnitude harder, and generally needs to be specially tailored for one specific version of one specific browser.
Re: (Score:2)
Re: (Score:1)
Exploits as well exist in almost any code that parses complex data coming from outside (loaders for PNG, JPG, HTML, WEBM...)
WebAssembly and SIMD (Score:2)
It's kind of a hack, but it gets the job done. Basically you have types like float32x, int32x4 etc. There are methods to add and subtract them using non vector code but if the hardware supports them using vector instructions, those vector instructions get substituted for the non vector code.
https://github.com/tc39/ecmasc... [github.com]
Re: (Score:2)
Is it implemented anywhere? From what I was able to quickly find, it is an _idea_ that somebody in future might be bothered by replacing it by true vector instructions, but nobody yet implemented it, so currently it will always fallback to polyfill. It would be great if you could point to changeset which implements it in natvely in one of major browsers.
Re: (Score:1)
They're working on it it Chromium
https://bugs.chromium.org/p/v8... [chromium.org]
However this page
https://peterjensen.github.io/... [github.io]
Complains that SIMD isn't implemented in Chrome 62, and unfortunately it's not implemented in Firefox 57 either.
So the answer is probably no, not yet.
Last time I used SIMD I used the Intel intrinsics in C++. Which are OK, but Visual Studio's C compiler didn't do a particularly good job at generating efficient assembler. Mind you, a vectorizable algorithm will still run faster using the intrins
No, it's STILL unthinkable (Score:2)
The word you should have used was "impossible" but even today it's unthinkable. I mean, key-rist, why the hell would anyone want to work in JavaScript? Blech.
One problem I have with JavaScript games (Score:2)
I suspect after several years the games, if unmaintained to the latest whiz-bang JS frameworks, will bitrot and newer browsers will cease supporting older javascript feature. I've seen this happen before when JavaScript was younger. And not much has been done to address the interface and feature stability of the language. We'll still be at the whims of the policies set by the top web browsers.
Maybe a little game isn't worth having 20 years later. But there are plenty of cases where old C/C++ code is brought
Re: (Score:2)
I suspect after several years the games, if unmaintained to the latest whiz-bang JS frameworks, will bitrot and newer browsers will cease supporting older javascript feature.
DHTML Lemmings [oldgames.dk] still works and that was last updated in 2004. I'm using Firefox and DHTML Lemmings was released before Firefox was [tweakblogs.net].
Their candid honesty is quite refreshing (Score:1)
Re: (Score:2)
The... Web?
Re: (Score:2)
It runs perfectly fine for me on an old budget laptop. Movement is smooth, with no stuttering or slowdowns. I expected it to be a total flop once I saw the Unity logo.
I can only assume that you're trying to run this on your Kaypro II.
Still, that demo is a pretty stupid choice. There are many more interesting demos that better showcase the capabilities of modern browsers. That this is what they selected tells me more about the website operators than it does about WebAssembly.
Re: (Score:2)