BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Binary AST Proposal Could Improve Performance of Large JavaScript Apps

Binary AST Proposal Could Improve Performance of Large JavaScript Apps

Bookmarks

Binary AST is a stage 1 proposal for the JavaScript language. Binary AST aims to drastically improve the load time of large JavaScript applications by adding a new, binary encoded abstract syntax tree (AST) to the language inspired in part by WebAssembly.

JavaScript web applications have been steadily growing bigger and more complex, with initial loading times becoming a significant performance bottleneck While JavaScript engines continue to improve their parsing performance and tools like minifiers and lazy loaders help reduce the initial load time, the underlying problem remains - parsing JavaScript is inherently slow.

Parsing JavaScript code is done with the help of an intermediate AST which then gets sent to the JIT compiler. The binary AST proposal seeks to simplify the parsing process by providing a pre-processed AST. While browsers still need to create a complete AST, the process would become much quicker.

Generating the binary AST helps browsers tackle three limitations with the JavaScript language:

  1. Information not available where needed (often caused by language features such as variable hoisting or inner functions)
  2. JavaScript's early error semantics (requires the upfront parsing of every JavaScript file)
  3. Inefficiencies in using characters (ambiguity at the character-level about what type of expression a JavaScript syntax is encoding)

While we cannot easily solve these limitations as they relate to core concepts within the JavaScript language, we can move part of the parsing to the build process. Although JavaScript doesn't require a build step, most complex JavaScript applications already include one. The build process is currently being used to bundle/minify the code, add polyfills, transpile source code from TypeScript, etc. The required build tooling is already present, and the change should have little effect on the build process for most complex applications.

Initial tests were done using a prototype implementation of the Binary AST within the Firefox browser and facebook.com static newsfeed benchmark.The time required by the browser to create a full AST (without verifying annotations) was reduced by ~70-90%. This improvement provides a considerable reduction, considering the base AST construction time was 500-800 ms. There have also been small improvements to file size compared to plain JavaScript,

The binary proposal is being championed by Mozilla, Facebook, Bloomberg, and Cloudflare. While there has been considerable interest in the Binary AST proposal, preliminary work is promising, and initial support is already present in Firefox, it still has several stages to pass before it gets accepted into the JavaScript language.

Rate this Article

Adoption
Style

BT