Refactor as a Node module
We should use Neon to expose this library to Neon. This would open the library to a larger community and save us from all JSON (de)serialization and IPC communication.
Another alternative would be to use wasm-bindgen and compile it to WebAssembly.
I would also be interested in adding a binast output in Babel. We just need a way to call it from JS.
@xtuc I had this idea, But I am afraid with the amount of JSON works that we are doing here, it would result in a huge binding file with wasm-bindgen (when we need some boundary crossing).
With Neon, the boundary crossing has a performance impact not a memory impact, which will force us to reduce the boundary crossing. WDYT?
Regardless, we'd need to refactor away the parsing. Parsing would look very different in a JS-based world.
@xtuc, @sendilkumarn does either of you know if there is a good way to send a JSON object to the webassembly world? Or does this need to wait for TypedObjects (or whatever they are called now)?
Good question, i'm not aware of any simple solution.
I would put the JSON string into the memory and extract/parse it from JS.
So, the steps would be:
- parse with Node-level parser (Babel, Shift, ...);
- convert the parsed object into BinAST's ES6 format;
-
JSON.stringifythe result; - call the wasm module;
- parse the string from Rust.
Is that it?
edit Removed word "native".
Ah I had the other way around in mind, sorry.
- Native is super confusing, you mean from existing tooling? Like Babel
- and 3. will be very expensive?
Before the 4. you need to put the JSON string into the module's memory (using the WebAssembly.Memory object in js).
I'm sure that we can find a common more efficient format between JS and Rust, similar to https://github.com/firejune/struct.js/tree/master for C.
Native is super confusing, you mean from existing tooling? Like Babel
Edited to remove the word "native".
- and 3. will be very expensive?
-
is one tree walk, should be reasonable;
-
is pretty expensive, although given the number of things we do in the Rust side, I'm not sure it's the critical cost.
Yes I agree, it's at build/compile-time so the performance shouldn't be critical.
- convert the parsed object into BinAST's ES6 format;
Do we have some parser already available for this?
Do we have some parser already available for this?
That's the role of shift::FromShift. It's imperfect and currently limited to a subset of ES6, but it works well enough for the moment.
IIUC
1,3,4 >> Happens in JS 2,5 >> Happens in Rust
Is that correct ?
Yeah, but 2 should probably move to JS.
That's a good question, I would assume that 2 would be faster in Rust and doesn't has to be in JS.
if 2 is faster in rust, then won't it be better to handle 2,3,4,5 in Rust. I am worried about the boundary crossing...
Else we have to rewrite 2 in JS
If we want the core to work with several parsers, 2. should be kept close to the parser, so in JS.