GithubHelp home page GithubHelp logo

happy-ferret / binjs-ref Goto Github PK

View Code? Open in Web Editor NEW

This project forked from binast/binjs-ref

0.0 1.0 0.0 4.08 MB

Reference implementation for the binjs format

Home Page: https://yoric.github.io/binjs-ref/binjs/index.html

Rust 100.00%

binjs-ref's Introduction

Travis status

About BinJs

As websites become more sophisticated, the amount of JavaScript source code keeps increasing. By itself, this is not a problem. However, with the amount of code loaded by large websites such as Facebook's chat, it is now common to witness page loads during which both the loading and the parsing of JS code can take several seconds each โ€“ this is assuming a fast connection, and taking into account that the code is both compressed and optimized for loading and parsing speed.

There is no reason to believe that the size of JS code will decrease or will even stop increasing, nor that every large webdev team has the means to profile loading and parsing speed of all their code.

This repo offers a (WIP) reference implementation for BinJs, a vendor-neutral JavaScript format designed to optimize parsing speed and, when possible, loading speed.

The BinJs format is not designed to be read or written by developers. Rather, we expect that the toolchain, both server-side and browser-side, will generate (respectively parse) BinJs files, letting BinJs files be used transparently for communication between the browser and the server.

Testing it

  1. Install dependencies (you will need npm)
npm install babel-core
npm install babylon
npm install mktemp
  1. Pull the code.
  2. Build the code.
cargo build && cargo test
  1. Running examples
./target/debug/examples/encode source.js dest.binjs
./target/debug/examples/decode dest.binjs source.js
./target/debug/examples/roundtrip source.js

Compatibility with JavaScript source code

The BinJs format is designed to preserve the semantics for all syntactically correct files.

Not preserved:

  • actual semantics of syntax errors;
  • source code positions;
  • formatting (including whitespaces and semicolumns);
  • comments (including source maps).

Expected benefits

The BinJs format is designed so that the VM can start parsing the file as soon as the first few bytes are received.

The BinJs format is designed to be generally faster to parse than JS source, thanks to a syntax that requires no backtracking, strings that do not need interning more than once, etc.

Furthermore, parsing a JS source is specified for a specific encoding, which means that many encodings need to be transcoded before they can be parsed (or, at best, while parsing), which slows down parsing. As BinJs is a binary format, it does not need any form of transcoding.

Finally, most modern JavaScript VMs support a form of lazy parsing, which performs faster parsing without most memory allocations. The BinJs format is designed to make lazy parsing more efficient, by letting parsers jump over subtrees (e.g. functions) in a single operation.

Benchmarks

WARNING These benchmarks have been done with an early prototype of BinJs. Actual implementations may end up with entirely different results.

These benchmarks do not attempt to measure the impact of early parsing.

Firefox DevTools snapshot

Size (gzipped): -72% Total parsing time:

Facebook chat snapshot

(total size/time for 152 files)

Size (gzipped): 2541kb => 2403kb (-5%) Total parsing time: -72% without skipping, -94% skipping all functions

Specifications

All (WIP) specifications may be found in the modules that implement them. See the documentation.

binjs-ref's People

Contributors

yoric avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.