oxc/napi/parser
Herrington Darkholme c63f5123b3
feat(parser/napi): add flexbuffer to AST transfer (2x speedup) (#1680)
Hi! I have created a proof of concept of improving using oxc in
JavaScript. The method is not polished but it provides valuable insights
for future direction!

Feel free to close~ It is for reference only :)

# Context 

This is a proof of concept implementation of passing binary AST to
JavaScript. JavaScript can selectively read flexbuffers-based AST nodes
on demand to avoid the deserialization toll. More context
[here](https://dev.to/herrington_darkholme/benchmark-typescript-parsers-demystify-rust-tooling-performance-2go8).

# Changes

* Add a `parseSyncBuffer` napi method to return a binary AST from Rust
to JavaScript. The AST is in flexbuffer format.
* Add a `test_buffer.js` to test usage of flexbuffers in JavaScript. It
is in cjs format because flexbuffers does not support ESM :/

# Result
Some preliminary results, for reference only.

```
~ node test_buffer.js
testJSON: 4.043s
testBuffer: 2.395s
```

Buffer based API is 100% faster than JSON.

# Future Ideas
* Flexbuffers itself is slow. A better binary protocol is desired!
* Using binary reader to traverse AST is undesirable. A proxy-based API
to emulate object behavior will be nice.
2023-12-15 02:52:33 +00:00
..
src feat(parser/napi): add flexbuffer to AST transfer (2x speedup) (#1680) 2023-12-15 02:52:33 +00:00
.gitignore refactor: change @oxidation-compiler/napi to oxc-parser (#1209) 2023-11-10 06:17:05 +00:00
build.rs refactor: change @oxidation-compiler/napi to oxc-parser (#1209) 2023-11-10 06:17:05 +00:00
Cargo.toml feat(parser/napi): add flexbuffer to AST transfer (2x speedup) (#1680) 2023-12-15 02:52:33 +00:00
index.d.ts feat(parser/napi): add flexbuffer to AST transfer (2x speedup) (#1680) 2023-12-15 02:52:33 +00:00
index.js feat(parser/napi): add flexbuffer to AST transfer (2x speedup) (#1680) 2023-12-15 02:52:33 +00:00
package.json feat(parser/napi): add flexbuffer to AST transfer (2x speedup) (#1680) 2023-12-15 02:52:33 +00:00
pnpm-lock.yaml feat(parser/napi): add flexbuffer to AST transfer (2x speedup) (#1680) 2023-12-15 02:52:33 +00:00
README.md feat: Release resolver with NAPI (#1212) 2023-11-10 15:25:17 +00:00
test.mjs refactor: change @oxidation-compiler/napi to oxc-parser (#1209) 2023-11-10 06:17:05 +00:00
test_buffer.js feat(parser/napi): add flexbuffer to AST transfer (2x speedup) (#1680) 2023-12-15 02:52:33 +00:00

Installation

corepack enable

Build

pnpm install
pnpm run build

Test

pnpm test