SoFunction
Updated on 2025-03-06

Learn more about JavaScript's WebAssembly

WebAssembly for JavaScript

Firefox 52 released this week has added support for WebAssembly, becoming the first browser to support the WebAssembly standard, and other browsers such as Chrome 57, Safari and Edge will also support WebAssembly one after another. WebAssembly originated from a project initiated by Mozilla, designing supplements rather than replaces JavaScript. It is a binary format that is easy to translate to native code. Its local decoding speed is much faster than JS parsing, making it possible for high-performance web applications to run on browsers, such as video games, computer-aided design, video and image editing, scientific visualization, etc.

In the future, existing productivity applications and JavaScript frameworks may use WebAssembly, which can significantly reduce loading speed and improve operating performance. Developers can integrate WebAssembly libraries for CPU-intensive computing into existing web applications.

Have you heard of WebAssembly? This is a project on universal binary and text formats for the web, jointly initiated by several major companies such as Google, Microsoft, Mozilla, Apple, etc. Let’s take a look at what WebAssembly is now? Why its appearance and future development are closely related to each of us, even if you are not a programmer/yuan~

At least to some extent, it will change the web ecosystem.

JavaScript – Assembly Language for the Web World

We have many development specifications for web applications, and these well-designed specifications make the work of web developers easier. It is hard to imagine that we create and websites or applications that we have no rules, programming languages, frameworks, and development concepts to follow.

And the web specification that puts all these things together has a well-known name:JavaScript !

JavaScript has basically become the standard development language for the web platform. As more and more software becomes a web application, JavaScript has made great progress.

But in the past few years, we have seen more and more projects coming out, trying to convert other language code into JavaScript by developing compiled programs, so as to enable developers to overcome some of the shortcomings of JavaScript itself. Some of these projects focus on adding new features to programming languages, such as Microsoft's TypeScript and Google's Dart, or speeding up JavaScript execution, such as Mozilla's project and Google's PNaCI.

In the default environment, JavaScript documents are actually simple text files, which are first downloaded from the server, and then parsed and compiled by the JavaScript engine in the browser. Users can communicate with the server while browsing web pages through Ajax technology.

On the browser side, JavaScript is currently used to implement dynamic interaction with users and other functions. Although many JavaScript frameworks are committed to performance optimization, a system based on bytecode will still have faster and better performance performance.

So, what the hell is WebAssembly?

WebAssembly is a new bytecode format. Its abbreviation is ".wasm", with .wasm as the filename suffix, which is a new underlying secure binary syntax. . It is defined as a "lite, short load time format and execution model" and is designed as a Web multi-programming language object file format.

This means that the performance on the browser side will be greatly improved, and it also allows us to implement a collection of underlying building blocks, such as strong-type and block-level scope. (Original text: And it gives us access to a set of low level building blocks, such as a range of types and operations.)

But don't make a mistake, this does not mean that WebAssmbly was born to replace JavaScript~ As Bjarne Strousup said, "JS will live well because there are only two types of languages ​​in the world: one is constantly criticized by people, while the other is useless!" And Eric Elliott believes: "It is better not to treat WebAssembly as just a programming language, but it is actually more like a compiler."

From to WebAssembly?

Is a strict subset of JavaScript that can be used as an underlying, efficient compiler target language. It provides an abstract implementation similar to a C/C++ virtual machine, including a large binary heap that can be paid and stored, integer and floating point operations, advanced function definitions, function pointers, etc.

The idea is to use the methods it stipulates to write JavaScript code, and the supported engines will transform the code into very efficient machine code. If you are compiling C++ code to, you will get a huge performance improvement on the browser side. The advantages of webassembly are mainly related to performance. According to the description of WebAssembly FAQ: On mobile devices, for a large code base, parsing alone takes 20-40 seconds, and experiments show that WebAssembly loads 20 times faster, mainly because the JavaScript engine deciphers binary formats much faster than parsing code.

What's the good thing about this thing?

You may ask, "Why are everyone talking about WebAssembly?" This is because WebAssembly is definitely a huge improvement for JS, but we often ask ourselves, "Is this enough?" Of course not, WebAssembly also has extraordinary significance for browsers. WebAssembly-enabled browsers can recognize text in binary format, and it has the ability to compile binary packages that are much smaller than JS text. This will bring a performance experience similar to that of local applications to web applications! What do you think is great? ! If the browser has to parse the complete JS code, it will take a lot of time (especially on mobile platforms), and the browser's decoding of the WebAssembly format is obviously much faster:) Here is a speech address of the JS author BE master (you tube, FQ required): Brendan Eich on JavaScript Taking Both the High and Low Roads - O'Reilly Fluent 2014

Who has fallen into the trap of WebAssembly?

Including Google, Microsoft, Mozilla is just a few companies on this long list. The project leads the people launched the WebAssembly Community Group, and the team's vision is to "enable browser manufacturers to cooperate on a new, lightweight web encoding format." However, the WebAssembly project has just started. Although it has a wonderful beginning, it still has a long way to go before WebAssembly becomes a popular web standard.

Why does this thing affect every web developer

Because webassembly allows developers to choose languages ​​that were not used to develop web applications for web development, or they can continue to use simple and easy-to-use JavaScript! The W3C WebAssembly Community group gives some use cases for WebAssembly, which show how WebAssembly makes it easier for web developers to work:

  • Some languages ​​with higher execution efficiency can be compiled into code executed on the web platform.
  • Provides developer tools on the browser side
  • Faster enterprise-level application client (for example: database)

WebAssembly has many uses. Let me give you a few tips: WebAssembly can be embedded in already developed JavaScript/HTML code; or the main framework of an application can be used with WebAssembly modules (such as animation, visualization, and compression, etc.), while the user interface can still be mainly written in JavaScript/HTML language.

Less simplified code, better performance, fewer bugs?

According to WebAssembly's development team, using WebAssembly means less original code. Compared to this, it reduces the amount of code by about 25%. Although this is just a prototype.

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.