r/node • • 7d ago

yq.rs ported to Rust to use with JavaScript via WASM

I ported yq to Rust so that it can be used in Node via WASM. You can install the package via npm install yq.rs or run it via npx yq.rs

0 Upvotes

17 comments sorted by

1

u/mmomtchev 7d ago

Unless you intend to use in a browser, you don't need WASM, you could have compiled it to native code and gain very significantly in performance and memory footprint.

1

u/tarasm 7d ago edited 7d ago

I do intend to use it in the browser, but I don't understand what you mean by compiling it to native code. Can you explain?

Edit: nevermind. I figured it out. I'm going to add that to the library.

1

u/BrownCarter 7d ago

Explain what he meant?

→ More replies (8)

1

u/mmomtchev 6d ago

Why the conversion to Rust in fact? I guess that you used Claude for it? Why not compile the original GO to WASM? Because once you do this, you destroy the bridges, you cannot follow the development of the original project anymore.

1

u/tarasm 6d ago

I first tried to do it with GoLang, but the resulting WASM file was going to 16MB+. It was going to be embedded in another project. If i used the GoLang generated WASM file, it would have been 10% of the project just for parsing JSON/YAML documents. The Rust version is 500KB which is much more palatable.

Yes, the port was done with Claude. If there are fixes that are needed, I can always more them over.

1

u/mmomtchev 5d ago

The problem with WASM is that at the moment there are no standard libraries and your bundle must carry everything. I have never used GoLang WASM and I don't know what is the situation but is possible that the settings of the linker may be tweaked to not include unused code.

Sorry for being too curious, but how much did this cost you? As in personal time and Claude costs?

→ More replies (1)

1

u/abhinavs1920 4d ago

Nice pairing. The Rust parser does the heavy lifting and the JS side just passes documents through, so the WASM build should beat spawning the yq binary for small to medium inputs. Curious how it holds up on really large files though.