WebAssembly It's a kind of Web A new method of running code on . Behind it are large technology companies , It promises to revolutionize our writing Web
Application mode , But it also has its own quirks and limitations .WASM Frame is like React In this way JavaScript Is the library a viable competitor ?

<> What is? WebAssembly?

WebAssembly or WASM Is all Web Browser can understand and run the second general ​​ programing language . however , You won't be alone WebAssembly
Script in —— It is a low-level assembly language , Designed to be very close to compiled machine code , And very close to native performance .

WebAssembly The magic of is that it is low enough , It's actually a simple one Compilation target . Any fairly fast language must ​​ Must pass the compiler at some time , Even like JavaScript
In this way JIT Compiling language , Usually this means compiling into x86 or ARM Machine code can run on modern processors .

however , You can also compile into different formats ; Usually this will eventually become closer to the final machine code “ lower ” language . for example ,Java Compile to send to JVM Runtime Java Bytecode , and C#
Compile to send to .NET Runtime Microsoft Intermediate language (MSIL). You can even convert a language from a high-level language “ transformation ” To another language , The most common extensions are
TypeScript reach JavaScript, But it can also be a more strange extension than you expected , for example Python reach JavaScript, Although this is usually chaotic and flawed .

WASM It's just an intermediate language that's easy to compile . in fact , It and Java Bytecode and C# MSIL
The concept of is almost identical —— Both formats make it easy to run the same code across platforms , Use the same format that runs on a specific runtime made for each platform .
This actually means JavaScript No longer, you can Web The only language running on .Web Browsers can now run in any language , As long as the language has WebAssembly
compiler .

Even like C++ and Rust Such a traditional desktop language can also be relatively easily compiled into WASM;AutoDesk Be able to have them in a few months 35 Years old C/C++
Code base migration to WASM , and Google Transplanted Google Earth, Both can render complex 3D Scenarios and run with near native performance .Unity
Game engines can also be WASM Medium operation .

WASM Currently in 94% Run in the user's browser , as usual ,IE,UC Browser and Opera Mini Support is the main factor hindering it . however , It got from
Mozilla,Microsoft,Google and Apple Developer Support , And its support in modern browsers is developing rapidly . With most Web
Same standard , It currently consists of W3C Standard organization management .

<>JavaScript Is no longer the only option

Great , So what does this mean for everyone ? ok , Although running in a web browser 《 Doom 3》 It's a cool demonstration, of course , But it doesn't completely change the rules of the game .

up to now ,JavaScript
It has always been your only choice to make web pages interactive . Whether you like it or hate it , Its design has never been used as it is today . It is a scripting language , Designed to accomplish some trivial tasks , For example, animate the drop-down menu , And it has been cracked
25 Years of running modern workloads . Only by using the most advanced JS Engine and JIT Optimized compilation , It can even be compared with native speed .

therefore , As the web page develops into a complete Web application program ,React,Vue and Angular etc. JavaScript
The client framework came into being to meet the needs . of course , There is still a server-side framework —— Are you from WordPress Reading in , One PHP
frame —— However, the client framework provides a huge performance improvement . Using the client framework , After pressing a button or interacting with an application ,DOM
Automatically updated . Even a framework rendered by a real-time server must issue a network request to change anything , And in the worst case , The entire page must be refreshed .
Web What innovation is really needed React Use this non JavaScript Suitable competitors for language written frameworks .

Although all Web The front-end code is used JavaScript Written , But back-end code is usually not . In high performance data center workloads , Use appropriate desktop language ( as
C#,C++,Rust and Go) Usually beneficial . after all , These can meet the same needs by requiring fewer servers , This will save you money .

however , This will also take your development time , Because now you have to deal with C# Backend and JavaScript
Interoperability between front ends . Simply cannot share code , Models and libraries can add as much complexity to your development as possible 2 Times the use of a unified system . That's the reason NodeJS
Why server backend is so popular , although 20 Years ago, this sounded like a bad idea .

Able to write on the server And running on the client C#,C++,Rust and Go The code will open the door to more options , And almost completely unnecessary JavaScript
As a programming language . stay WASM Client Framework Blazor in ,JavaScript The use of is reserved for interoperability with existing client packages and basic scripts .

<>WASM How does the client framework work ?

because WebAssembly Just a kind of “WebAssembly environment ” How to run code in , So you can think of it as running Docker container . for example , Microsoft
Blazor frame ( By far the most popular WASM Client Framework ) There are two modes of operation :

* Blazor The server , It runs all processing and rendering on the server , And pass WebSocket Send updates to HTML DOM, as well as
* Blazor WebAssembly, It does exactly the same thing , But now the processing and rendering is on the client through WASM Compiled .NET Completed at runtime .
In the latter case ,WebSocket The connection is replaced with a direct link to DOM, adopt JavaScript, because WebAssembly Cannot call at this time without JS API
Modify directly in case of DOM. in any case , You also need JavaScript come “ guide ” WASM application program , therefore JS It won't disappear soon .
besides ,WASM The client framework usually works like any other framework , The details will depend on the implementation .

for example ,Blazor Maintain the internal state and trigger the re presentation of the application when a button is clicked or input is made . It is used in WASM Running on C# Code construction new HTML, Then put the
HTML Send to JavaScript API To apply to DOM. stay WebAssembly
Performing this operation on the server can reduce the processing load on the server , Make the client respond quickly . Even through JavaScript visit DOM A little slower, too , But it's still better than passing Internet visit
DOM The alternative is much faster .

<> How fast do we talk ?

“WASM How fast ?” Question of It's hard to be sure . Overall , It's obviously faster , There is no doubt about it , But in some cases , It's more complicated than that .

DOM Access remains a problem , Because it must pass JavaScript complete , So it's like JavaScript
As slow . however , This will be solved soon . Sometimes ,JavaScript stay WASM It may be faster in specific benchmarks that the compiler may encounter , It's just because JS Behind 25
Compiler iteration in .

For high-performance applications that require a lot of processing power , For example, games and Applications ,WASM Usually fast 1.5 Times to 2 times . But it may be the same speed . It may also be better than JavaScript slow
20%. For some functions , It can also be fast 10 times . There are benchmarks showing all these results , So the only certainty is that your mileage will be different .

Compared with native code , It may always be slower than the language it compiles . therefore , Although it may be soon , But there are many warnings , And you shouldn't expect to Web For native performance on WASM.
in summary ,WASM It doesn't take crazy performance to be revolutionary . It just needs to work , Not slow , And supports multiple languages .

<> What frameworks work now ?

The most important one so far is Blazor, from Microsoft development . This is the first one supported by a large company WASM Client Framework , And may become WASM
Finally get the mainstream catalyst it deserves .

Blazor WASM It's only a year old ,Blazor Server Yes 3 Released years ago , but Blazor The great thing about is that it's just ASP.NET
Extension of , This is a 20 Years old Web frame ,Microsoft Constantly improving . You can use many that have been ASP.NET
Front end library written by , It is likely to be the only one that can be associated with NPM Comparable Web Framework supported by package manager .

This is not a sideline —— Microsoft has been pushing Blazor Not just one Web frame . This is their next application programming model . They are developing Blazor
Desktop, Will be 2021 Released at the end of the year , Its working principle and Electron Run the same on the desktop Blazor Web
Applications are very similar . They are obviously very concerned about it , This pair WASM Generally speaking, it's good news .

If you want more information , We can read about Blazor A guide to what it is and how to start using it .

Another framework that can be used in production is Yew, It is based on Rust upper ,Rust Is similar to C++ Modern language , But it is memory safe because of the strange way it handles references .Yew
Fast speed , support React And other component-based models , And with JS API Interoperability .
asm-dom Is one for C++ Written Library , It will C++ Connect code to DOM I didn't do more than that . obviously , You need to bring your own frame here , But most are crazy enough to use C++
to write Web Application developers may still do this . It also supports fallback to asm.js, This is WebAssembly Trying to be an earlier version of . It's basically
JavaScript A subset of , Integer only ( Namely , Bytes only , Not objects ), This makes it possible to C++ Code conversion to easier , Because it's basically all C++
Code used at the end of the day . Having this support is not very useful , Because few environments do not support it WASM But will support asm.js.

Vugu It's a Go Prepared framework , Support components and Vue Syntax as model , But it is still in the experimental stage . also Vecty, It is also a popular Go frame .

<>WebAssembly The future of

It's all focused on use WASM operation DOM And build the client of the application Web On the frame . however , You can also migrate the entire desktop application to the network . This is it. Uno
Done —— use WASM Directly in Web Run general in container Windows platform (UWP)
application program , This also brings the added benefit of being completely cross platform . Its effect is actually a little incredible , And it really feels like you're using this machine Windows application program . You can view it yourself in their gallery .

WASM Ecosystems are more than that . If you want to know more , You should read GitHub Upper awesome-wasm compile , It lists a bunch of popular items .

The most noteworthy thing we haven't mentioned here is WASI—— one kind Run portable on any system using standardized system interfaces WebAssembly Method of . along with WASM
Getting higher and higher performance ,WASI May prove to be a viable way to run any type of code on any type of system , be similar to Docker
How do you work , But not limited by the operating system . in fact ,Docker The creator of Solomon · Hicks (Solomon Hykes) Has wholeheartedly endorsed it :
WebAssembly Only a few years old . It still has a lot of room for growth , And still accelerating . Five years later ,Blazor and Yew And other frameworks will work with React,Angular
and Vue As common , This is not unreasonable .

This can be said to be scattered Web ecosystem , but WASM It is cross platform . WAPM It's a WASM Package manager , It may become the preferred way to share libraries between frameworks in different languages .

in any case , stay WebAssembly Running on Web The framework has great potential , And in Microsoft With personal support , We believe they are Web The future of .

Technology
©2019-2020 Toolsou All rights reserved,
Dynamic Simple registration login interface HTML+CSS+JQCSS Implement overflow display ellipsis 802.11 CCA and NAV mechanism Programmer refused due to low salary offer,HR become shame , Netizens instantly blew up ..abaqus Value of mass scaling factor _ABAQUS Mass scaling for Java Student information management system console version C Classic topics of language —— Insert a number into the sorted array Computer level 1 multi-point , How many points can I pass the computer test level 1 VINS-Fusion run kitti stereo and stereo+GPS data TS stay vue2 Writing in the project