Web Assembly

Web 应用程序较于原生应用之短在于性能。当然性能的问题不在于比较跑分高下,而在于用户体验。试想象一下,浏览器直接执行的游戏引擎代码是优化过的二进制中间表达形式(IR),甚至可能是缓存下来的后端转换过的机器码。WebApp与Native App再战一轮?

谷歌等巨头拟推全新网络应用标准WebAssembly,旨在提高编译后Web应用程序的性能。

Google/微软/苹果联手:浏览器提速20倍! WebAssembly是一种可用于未来浏览器中的字节码(bytecode),可使浏览器性能提升20倍。字节码是一种机器可读的指令集,与高级语言相比,字节码的加载速度更快。WebAssembly项目旨在开发全新的字节码,从而让桌面和移动端浏览器变得更高效。

W3C WebAssembly Community Group

GitHub WebAssembly Organization

Note:

WebAssembly Design Documents

High Level Goals

  1. Define a portable, size- and load-time-efficient binary format.
  2. Specify and implement incrementally: Minimum Viable Product (MVP) primarily aimed at C/C++, polyfill, essential post-MVP features, future features.
  3. Design to execute within and integrate well with the existing Web platform.
  4. Design to support non-browser embeddings as well.
  5. Make a great platform: build a new LLVM backend for WebAssembly and an accompanying clang port; promote other compilers and tools targeting WebAssembly; and enable other useful tooling.

FAQ

  1. Why create a new standard when there is already asm.js?
  2. What are WebAssembly’s use cases?
  3. Can the polyfill really be efficient?
  4. Is WebAssembly only for C/C++ programmers?
  5. What compilers can I use to build WebAssembly programs?
  6. Will WebAssembly support View Source on the Web?
  7. What’s the story for Emscripten users?
  8. Is WebAssembly trying to replace JavaScript?
  9. Why not just use LLVM bitcode as a binary format?

Use Cases

How WebAssembly can be used?

  1. Entire code base in Web Assembly.
  2. Main frame in Web Assembly, but the UI is in JavaScript / HTML.
  3. Re-use existing code by targeting Web Assembly, embedded in a larger JavaScript / HTML application. This could be anything from simple helper libraries, to compute-oriented task offload.

Other Documents

  1. AST Semantics: Abstract Syntax Tree Semantics: types, linear memory, local/global variables, control flow structures, calls, literals, expressions with control flow, 32/64-bit integer operations, floating point operations; datatype conversions, truncations, reinterpretations, promotions, and demotions.
  2. Binary Encoding: portable binary encoding of the Abstract Syntax Tree nodes, designed to allow fast startup, which includes reducing download size and allow for quick decoding.
  3. Text Format: The text format is equivalent and isomorphic to the binary format.

Conclusion

WebAssembly is two things (at least):

  1. Standardized way across all the browser houses to enable hybrid applications – on many dimensions.
  2. Key component in Google OS convergence; kills NaCL and PNaCL.