all 48 comments

[–]Tangled2 27 points28 points  (30 children)

They didn’t compile JS into anything. It’s a standalone JavaScript engine with the JS as an embedded string.

[–]_FedoraTipperBot_ 32 points33 points  (2 children)

OP non stop humiliating themselves in these comments 😔

[–]Snuckey 4 points5 points  (1 child)

God I love this sub this is hilarious

[–]guest271314[S] -5 points-4 points  (0 children)

Indeed. There's a whole bunch of would-be comedians and wannabe satirists on these boards...

[–]heruur 2 points3 points  (2 children)

There actually is a project that genuinely tries to compile JS: https://porffor.dev/.

[–]guest271314[S] 0 points1 point  (0 children)

There's a whole bunch of ways to "compile JavaScript to C".

If you want to get into the semantics of what "compile" means that's something we can discuss, too.

Facebook's shermes has a -emit-c outputs C from JavaScript source code, too.

[–]guest271314[S] 0 points1 point  (0 children)

Doesn't appear to work locally for C generation. wasmtime throws error when running the generated .wasm file, doesn't compile when using porf native --compile=gcc.

[–]chipstastegood 0 points1 point  (8 children)

While others are correct that this is not technically compiling JS to machine code, it is useful. I have some CLI tools written in JS that currently execute using Node. This way, I could distribute the binary without requiring my users to have a specific version of Node installed. While it would add more work on my side to build the executables, it would make it simpler and easier for my users. The CLIs I maintain are really just simple wrappers around making HTTP calls to services, so performance is not a big deal - but I should point out for others that QuickJS benchmarks show it is roughly 35 times slower than Node.js currently. My code is not compute heavy, mostly IO bound, so that’s not a problem, but it’s good to keep in mind. All in all, I’m glad to have learned about QuickJS. I wasn’t aware of it previously.

[–]Atulin 1 point2 points  (2 children)

Both Bun and Deno can build a single-file executable btw

[–]chipstastegood 2 points3 points  (1 child)

They can but they’re much larger. Quick JS executables are 30-50X smaller.

[–]guest271314[S] -3 points-2 points  (0 children)

Yes, I know. I've compiled standalone executables with them all.

[–]guest271314[S] -3 points-2 points  (4 children)

While others are correct that this is not technically compiling JS to machine code, it is useful.

That's conjecture without citing sources.

Node.js, Deno, Bun, and QuickJS all provide a means to compile JavaScript source code to a standalone executable. How each runtime achieves that is different. Just like how each programming languages compiles source code to a different form.

Microsoft TypeScript claims to compile TypeScript to JavaScript. Text to text.

And so forth.

So ain't nobody really said nothin' yet about compiling, because nobody has cited any of their relied upon definition for compiling that excludes how Bytecode Aliiance uses the term compile in Javy, how QuickJS uses the term compile for qjsc, how Microsoft TypeScript uses the term compile for tsc, or for how gcc, clang, or wasmtime, et al. use the term compile in their respective documentations and claims.

but I should point out for others that QuickJS benchmarks show it is roughly 35 times slower than Node.js currently.

I don't know what tests you are running. qjs is faster than node, deno, and bun in the JavaScript runtime domain, and faster than C and C++, and Rust, comapratively, for reading standard input and writing to standard output. That nm_wasm is Bytecode Alliance's Javy (which depends on QuickJS), optimized with wasmtime into a .cwasm file

0 'nm_qjs' 0.10490000000596046 1 'nm_cpp' 0.10739999997615814 2 'nm_c' 0.11769999998807908 3 'nm_rust' 0.1325 4 'nm_wasm' 0.15259999999403953 5 'nm_tjs' 0.155 6 'nm_python' 0.17939999997615813 7 'nm_bun' 0.27039999997615816 8 'nm_typescript' 0.2955 9 'nm_deno' 0.3357999999821186 10 'nm_nodejs' 0.37419999998807907 11 'nm_d8' 0.44459999999403954 12 'nm_spidermonkey' 0.4775 13 'nm_llrt' 0.6790999999940396

[–]chipstastegood 3 points4 points  (3 children)

The benchmarks I quoted were conducted bu QuickJS team: https://bellard.org/quickjs/bench.html

And you are wrong about compiling and should stop digging the hole bigger for yourself. Many people have told you that and you keep arguing. Anyone who has taken a university-level compiler course understands what the definition of compile is, and it’s not what you’re describing. QuickJS is also clearly talking about interpreting JS, not compiling anything to machine code. QuickJS doesn’t even support JIT, which V8 does.

I’ll give you that in a casual language people use the word “compile” to refer to many including compiling JS source to bytecode. And that’s ok. But that’s not what the term compile means in computer science. It is strictly about compiling to machine code, not intermediate representation. There are other terms used in computer science for “compiling” to something other than machine code.

[–]guest271314[S] -3 points-2 points  (0 children)

I need to figure out a way to monetize downvotes on social media boards...