mirror of
https://github.com/danbulant/oxc
synced 2026-05-20 04:38:54 +00:00
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.
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
/* tslint:disable */
|
|
/* eslint-disable */
|
|
|
|
/* auto-generated by NAPI-RS */
|
|
|
|
/**
|
|
* Babel Parser Options
|
|
*
|
|
* <https://github.com/babel/babel/blob/main/packages/babel-parser/typings/babel-parser.d.ts>
|
|
*/
|
|
export interface ParserOptions {
|
|
sourceType?: 'script' | 'module' | 'unambiguous' | undefined
|
|
sourceFilename?: string
|
|
}
|
|
export interface ParseResult {
|
|
program: string
|
|
errors: Array<string>
|
|
}
|
|
/**
|
|
* Parse without returning anything.
|
|
* This is for benchmark purposes such as measuring napi communication overhead.
|
|
*
|
|
* # Panics
|
|
*
|
|
* * File extension is invalid
|
|
* * Serde JSON serialization
|
|
*/
|
|
export function parseWithoutReturn(sourceText: string, options?: ParserOptions | undefined | null): void
|
|
/**
|
|
* # Panics
|
|
*
|
|
* * File extension is invalid
|
|
* * Serde JSON serialization
|
|
*/
|
|
export function parseSync(sourceText: string, options?: ParserOptions | undefined | null): ParseResult
|
|
/**
|
|
* Returns a binary AST in flexbuffers format.
|
|
* This is a POC API. Error handling is not done yet.
|
|
*/
|
|
export function parseSyncBuffer(sourceText: string, options?: ParserOptions | undefined | null): Buffer
|
|
/**
|
|
* # Panics
|
|
*
|
|
* * Tokio crashes
|
|
*/
|
|
export function parseAsync(sourceText: string, options?: ParserOptions | undefined | null): Promise<ParseResult>
|