MCPcopy Index your code
hub / github.com/binast/binjs-ref

github.com/binast/binjs-ref @entropy-0.3.3

Chat with this repo
repository ↗ · DeepWiki ↗ · release entropy-0.3.3 ↗ · + Follow
10,305 symbols 40,092 edges 1,085 files 328 documented · 3% updated 5y ago★ 435109 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Travis Status

About the JavaScript Binary AST

As websites become more sophisticated, the amount of JavaScript source code keeps increasing. While depending upon a large JavaScript codebase won't prevent a website from working, it will cause websites to start slowly – often unacceptably slow. This is due to two bottlenecks: parsing and bytecode compiling JavaScript. Unfortunately, browsers have pretty much reached efficiency peak for both operations.

We (Mozilla, Bloomberg, Facebook, CloudFlare) are currently working on a domain-specific encoding for JavaScript, called "BinAST" (short for "JavaScript Binary AST"). The JavaScript Binary AST is designed to break the bottleneck. Current advanced prototypes already show JS parsing improvements of 30%-50% on all the most common frameworks, just by changing the format, and we believe that we can increase this improvement much further. The encoding can be built as part of a webdev toolchain, or injected by a proxy or CDN, hence automatically improving the performance of end users without change to the original website.

This encoding is currently in the JavaScript TC39 standardization process [3]. It can be used alongside existing compression techniques (gzip, brotli, etc.)

Testing it

  1. Install dependencies (you will need npm, rustup)
npm install
rustup install nightly
rustup default nightly
  1. Pull the code.
git clone https://github.com/binast/binjs-ref
  1. Compress/decompress.
cargo run --bin binjs_encode -- --help
cargo run --bin binjs_decode -- --help

Note The JS parser may choke on very large JS source files. If so, you'll need to set the environment variable NODE_MAX_OLD_SPACE_SIZE=xxxx. This will instruct the Node-based parser to allocate more memory. The default value is 2048 (Mb). This is equivalent to passing --max_old_space_size to the Node process.

  1. Dump tree structure.
cargo run --bin binjs_dump -- --help

Note binjs_dump supports only multipart format.

Compatibility with JavaScript source code

Preserved: - semantics of well-formed programs; - variable and function names.

Not preserved: - actual semantics of syntax errors; - source code positions; - formatting (including whitespaces and semicolumns); - comments (including source maps).

Expected benefits

The Binary AST 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.

The Binary AST format is designed so that the VM can start parsing the file as soon as the first few bytes are received (streaming parsing) and can start compiling the file to bytecode soon after that (streaming bytecode compilation).

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 BinAST 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 BinAST format is designed to make lazy parsing more efficient, if required, by letting parsers jump over (functions) in a single operation.

Specifications

  • The semantics are specified here.
  • The binary format is specified here.

Extension points exported contracts — how you extend this code

TokenWriter (Interface)
Build an in-memory representation of a BinTree. Implementations may for instance introduce atoms, maximal sharing, etc. [6 …
crates/binjs_io/src/io/mod.rs
FromJSON (Interface)
A data structure that may be imported from JSON. [11 implementers]
crates/binjs_shared/src/json_conversion.rs
ToStr (Interface)
Miscellaneous utilities. [5 implementers]
crates/binjs_meta/src/util.rs
Compare (Interface)
Compare two values JSON as elements of a given spec. Fields that are not part of the spec are ignored. [4 implementers]
crates/binjs_generic/src/syntax.rs
JSONGetter (Interface)
Utilities to simplify dealing with JSON. Most of these tools are useful largely because lifetime management in a mutabl [2 …
src/util/mod.rs
SourceParser (Interface)
A source that can parse files to JSON ASTs. [1 implementers]
src/source/parser.rs
Serializable (Interface)
A value that may be serialized to bytes, optionally compressed. [6 implementers]
crates/binjs_io/src/multipart/write.rs
ToJSON (Interface)
(no doc) [11 implementers]
crates/binjs_shared/src/json_conversion.rs

Core symbols most depended-on inside this repo

c
called by 209980
tests/data/facebook/single/iEgP7Vv3MrH.js
push
called by 6683
crates/binjs_io/src/binjs_json/write.rs
get
called by 4973
crates/binjs_meta/src/util.rs
c
called by 1072
tests/data/facebook/single/o7G0EczmD-6.js
Z
called by 848
tests/data/facebook/single/6d2pPNdw-Fq.js
add
called by 836
crates/binjs_io/src/bytes/atoms.rs
next
called by 621
crates/binjs_io/src/binjs_json/read.rs
c
called by 587
tests/data/facebook/single/GDWAoyDy3hk.js

Shape

Function 9,384
Method 708
Class 137
Interface 42
Enum 34

Languages

TypeScript90%
Rust10%

Modules by API surface

tests/data/facebook/single/qwqtBhLzQ8Y.js441 symbols
tests/data/facebook/single/kPs479ufKyg.js441 symbols
tests/data/frameworks/angular.1.6.5.min.js280 symbols
tests/data/facebook/single/6d2pPNdw-Fq.js268 symbols
tests/data/facebook/single/o7G0EczmD-6.js267 symbols
tests/data/frameworks/vue.2.5.16.min.js225 symbols
tests/data/frameworks/react-dom.production.16.3.2.min.js198 symbols
tests/data/facebook/single/aoGTCgaRyfh.js181 symbols
tests/data/facebook/single/NP0I7Z0wjpg.js178 symbols
tests/data/facebook/single/Dt-P-nVSHp5.js178 symbols
tests/data/frameworks/ember.2.18.2.min.js147 symbols
tests/data/frameworks/moment.2.22.1.min.js105 symbols

For agents

$ claude mcp add binjs-ref \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact