Live data from Hacker News

A small but complete JavaScript engine

bellard.org

11–20 of 151 posts

Re: A small but complete JavaScript engine

#11
> Can compile Javascript sources to executables with no external dependency.

Is QuickJS a viable way to write command-line apps in JavaScript? In particular, does it have enough of a standard library to work with, or would it be a struggle because (I assume) it can’t use packages from NPM?

I know there’s the alternative of bundling Node.js and V8 into an executable, but the resulting binaries are large - it feels like the command-line equivalent of using Electron.

Re: A small but complete JavaScript engine

#13
post #11

> Can compile Javascript sources to executables with no external dependency. Is QuickJS a viable way to write command-line apps in JavaScript? In particular, does it have enough of a standard library to work with, or would it be a struggle because (I assume) it can’t use packages from NPM? I know there’s the alternative of bundling Node.js and V8 into an executable, but the resulting binaries are large - it feels lik…

It's quite possible, especially for simple cli apps. The io is different from node though, so takes a little getting used to.

Re: A small but complete JavaScript engine

#14

Could this potentially be used in a browser? How complete is “complete”? Browser diversity is top of mind for me...

As far as does this implement enough JavaScript features for websites to run, https://test262.report/ looks really promising! You would have to hook it up to DOM and network and all sorts of other APIs normally provided by browsers, though.

One reason you might not want to build a general-use browser on QuickJS is performance. QuickJS is one of the fastest JS interpreters in its weight class, but engines like V8 achieve much better runtime speed by using fifty times the code to do all kinds of complicated just-in-time optimizations. Websites built in frameworks like React are often bottlenecked by JS engine performance (spending 100ms or more just doing tons and tons of object instantiations and function calls and stuff), so a QuickJS browser probably wouldn't provide a good experience for those.

Re: A small but complete JavaScript engine

#15

Could this potentially be used in a browser? How complete is “complete”? Browser diversity is top of mind for me...

I believe it could be used. The biggest problem is that all of the DOM classes have to be replicated, and the api surface is absolutely huge, so that would take a large amount of work.

Re: A small but complete JavaScript engine

#16

Very cool. Wouldn't it be cool if someone wrote bindings for Linux system calls and provided an event loop for this engine - then you could write system software in JavaScript!

I realize you're joking, but a company called Samsung actually did something similar already: https://nodejs.org/

Re: A small but complete JavaScript engine

#18

Could this potentially be used in a browser? How complete is “complete”? Browser diversity is top of mind for me...

These individual technologies (DOM/html parser, js runtime, layout etc.) really aren't so bad. It's about a weekends worth of work to do one.

What makes a "modern" browser is all of these technologies together not just quirk free, but matching quirks with whatever browser is popular. Even this won't really be enough since most people also depend on a bunch of online services provided by browser vendors at this point (push, bookmark syncing, password management etc.)

Re: A small but complete JavaScript engine

#19

Very cool. Wouldn't it be cool if someone wrote bindings for Linux system calls and provided an event loop for this engine - then you could write system software in JavaScript!

I realize you're joking, but a company called Samsung actually did something similar already: https://nodejs.org/

Serious question, why is this a joke? Couldn't javascript be just another language to replace bash?

Re: A small but complete JavaScript engine

#20

Here's a really interesting video about speed performance of the v8 engine: https://www.youtube.com/watch?v=aC_QLLilwso The basic points: They watch functions for "hotness" (how often they are ran). Then, any function that is super hot, they'll see if it's being ran consistently (ie always receives two numbers as its arguments). Then they'll make a streamlined interpretation of the js code which only checks the argum…

A more useful starting point for comparison might be the projects' respective stated goals. This is the first one listed for QuickJS:

Small and easily embeddable: just a few C files, no external dependency

Whereas v8's project description opens with:

V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++. It is used in Chrome [...]

The stuff in the video is definitely super interesting but much of it is about how design goals in v8 are met.

Post reply on HN