QuickJS JavaScript Engine
bellard.org
bellard.org
The second project of his that I came across was https://en.wikipedia.org/wiki/Bellard%27s_formula and his page on π: https://bellard.org/pi/
I’d argue it is a whole lot more than most PhD thesis.
Fabrice is a wizard.
Just to learn that it is indeed the same guy (plus Charlie Gordon) :D
1. Are there anyone on HN knows him in real life?
2. Does anyone have other people in their mind who is in the same league as this man? Mike Pall's LuaJIT sort of make him at this level but that is only one thing. Fabrice create things that everyone are using it one way or another, and if it wasn't HEVC patents mess we would have his bpg [1] replacing jpeg.
bellard.org - has the most impressive portfolio of software created from a single developer I've ever seen. It's more astonishing how varied each of his accomplishments are - covering some of the hardest programs in different computer science fields.
He's by far the best programmer in my book, I'm not sure who I'd put at #2, there's a number of contenders, but anyone else I can think of are experts in their respective fields, I don't know of anyone who has compiled such a broad list of complex software covering that many different fields.
But that's mostly by choice as he's predominantly a professor who spends most of his time teaching so he's obviously going to have created a lot less body of digital works than a full-time developer is going to have.
I referenced this document a lot when writing my own Telnet stack.
There’s probably an interesting story hidden in there.
I played MUDs for several years, at the same time that I was learning the ins and outs of programming. I developed some plugins for a popular third-party client called MUSHclient. The game I played also had a somewhat proprietary first-party client, and they used a spare Telnet option (one left unassigned by IANA [1]) to pass data from the server to the client to drive some extra graphical widgets on their client. I got involved in developing plugins that made use of that data, which led me to learning how to negotiate that option with the server and get the data I wanted.
I eventually started developing my own MUD client, which is where the Telnet stack came in. Now, writing a Telnet stack is just something I do when I learn a new language. It's just large enough of a project to exercise some architectural and API-level concerns.
[1] If you're curious, all of the formally allocated Telnet options are documented here: https://www.iana.org/assignments/telnet-options/telnet-optio...
Definitely a legend!
I'm trying to put into words what the difference feels like. Git and linux demonstrate, for Linus, great intelligence but not genius, the way Ballard's works do. And on Linus' side, git and linux demonstrate leadership, pragmatism, and a tremendous understanding of how to actually drive a large project forward over time, which Ballard's works don't.
It is something I have little respect for and tbh it doesn't matter how clever it is when he spends most of that effort on for want of a better term intellectual wankery.
Possibly in his defense, I suspect it made more sense at the time. He'd just tell other hackers "this is free software - free as in...", and they'd say "OK, that's an interesting idea that resonates with what we know and see", or "OK, that's some hippie stuff, but we've been benefiting from that kind of sharing in computing, so you might have a point". They'd hear that in-person, or on the Internet, or in the text files when they went to compile and install the software. Now most people never get the introduction, or it's drowned out in all the massive noise that everyone is exposed to on the Web.
Though maybe saying "free" still works for him, because, when he's giving a talk, he can say "this is free software - free as in..." and people are there, paying attention.
Also, it's in the brand name.
A wild speculation possibility is that he's still thinking decades ahead, and maybe we go back to trying to say substantive things, and paying attention when others say substantive things, and then saying "free software" makes more sense again. (Some other instances of thinking ahead are the reason behind a subreddit name: "https://old.reddit.com/r/StallmanWasRight/")
In any case, I think it's unfortunate if people dismiss RMS's speech without listening, because of quirks and things we don't immediately understand.
Regarding lists like r/stallmanwasright, I work with plenty of smart people who couldn't care less about free software some of them aren't even tech savvy and they can spot all the problems with a lot of the services we have today.
I think it is more an exercise of throwing shit at a wall until and seeing what sticks. Which btw is a perfectly valid method of seeing how your message gets across but it doesn't make you a genius.
That combined with awful manners, hygiene and the fact that he has some disgusting opinions about child abuse. I can't stand the man. The fact that this guy has any importance past "Well he was the founder of the GNU project and he wrote a text editor" seems ludicrous to me.
This thread is pretty tangential to the post to start with, so there will be better occasions to discuss these things. And maybe it helps to separate them out differently.
https://www.amazon.co.uk/You-Are-Not-Gadget-Manifesto/dp/014...
He has a few chapters about problems (rarely mentioned) with GNU / GPL and Stallman himself.
Do you ask this to know if he's a real guy or an AI or a pseudo for group of persons like https://en.wikipedia.org/wiki/Nicolas_Bourbaki ?
I know Fabrice a little. He's definitely real, smart and humble.
Visited him at his workplace about ten years ago when he worked at Netgem.
We also have a common friend we visit with spouse and kids, where we discover and discuss new gadgets (physics-based, drones, mechanical puzzles, etc). One day we played with a kind of padlock where the lock procedure implied to move a sort-of 4-direction joystick. The trick was: you could do any number of moves to lock it. It seemed like it allowed to store an arbitrary long sequence of numbers in a finite mechanical system. Fabrice arrived, heard us explain, thought, and said "the mechanics probably implements some sort of hash algorithm". That was the answer.
He is definitely very humble and a very good listener. When he told us about this side project he was working on about a year ago, he made it seem like it wasn't a big deal, just a small js engine, would never compete with v8. After a few questions, it was clear that the goal was to implement the latest ECMAScript spec, with all the goodies. It will never be in the v8 league, but it's on a league of its own.
With how things are going now, V8 code is the de-facto "upstream spec"
Pike's account of how UTF-8 was invented is a fun read: https://www.cl.cam.ac.uk/~mgk25/ucs/utf-8-history.txt
What makes this JS implementation deserve the name "Quick"?
I noticed it doesn't appear to do JIT compilation or any of the fancy optimisations V8 does. So whilst it may start up quickly, and may interpret quickly, it won't actually execute JS quickly relative to V8, unless I missed something huge in the linked web page.
I got the sense there are several performance claims here that sound impressive but won't actually matter for nearly every JavaScript user.
It's not at all my field of expertise, but my guess is that problems with V8 are that it's an order of magnitude larger, that it's written in C++ rather than C89, that it's more likely to make large changes to the way it works, and that it uses more memory.
All of those are good decisions to make for a component of Chrome that helps run webpages. But sometimes you'll only want to make it possible for users of your less than massive technical application to script its behavior using a language they might already be familiar with, and then those properties are undesirable.
"Quick" calls to mind something that's not just fast, but nimble.
Despite my general distaste for JS largely due to websites tending to abuse it more than anything, this project is still immensely impressive and very inspiring, and one wonders whether there is still "space at the bottom" for even smaller but functionality competitive implementations.
Why would you have a distaste for JavaScript based on how others use it? JavaScript has evolved into an extremely powerful and flexible language which is taking many great lessons from other languages. Sure its not perfect but its a real workhorse.
EDIT: I know you're not meant to ask why the downvotes, but I do wonder in this case - the comment is a reasonable one, I guess it's the many JavaScript haters piling on - "Haters gonna hate". I stand by these comments - JavaScript is a flawed but great language that has only proven over time its flexibility and adaptability to become probably the single most used language - the people who don't like it are those who don't use it/understand it.
I like my languages a bit less flawed, thank you very much.
Languages don't exist in a vacuum. The way libraries are written and the way coworkers write code has a huge effect on us.
> proven over time its flexibility and adaptability to become probably the single most used language
Its usage has nothing to do with its quality. The web has a low barrier to entry, and well web devs have to use JS because browsers handcuff us to it.
If JS were so great, we wouldn't have increasing TypeScript adoption or a million compile-to-JS languages.
I've been writing JS for 20 years. I use bleeding-edge features, TypeScript, and Babel. I've done front and back end. It still sucks (which is sometimes the fault of V8, but not always).
Observe that Bellard's own site, despite having a few JS-based projects and demos, and now himself being the author of a JS engine, has not succumbed to the "JS everything!!!1" fad.
(FYI I didn't downvote.)
I've never heard my parents or non-developer friends complain about a site using too much JavaScript, but if I show them Hacker News or old.reddit.com, they'll complain it looks ugly and hard to read/use and really do lose interest in it immediately.
Anyway, I fail to see how this is a problem of JavaScript. Replace JavaScript with any other language in the browser and you'll see exactly the same abuse happen.
If you really dislike JS so much, do what I do and disable JavaScript in the browser. If a site doesn't work I don't use it. People on Hacker News seem to want the web to revolve around themselves but it never has done and never will.
How can they? They don't know what it is. They are complaining about it a lot of times you don't hear about it; every time they have to fill an abomination of a form, every time they hard-close their browser because it's stuck, every time they just wait for a page to load, every time 'something' happens they did not ask for but it happened anyway.
That's not the fault of JS but it is the problem of the ecosystem, the ease of use etc. Messing things up and 'good enough' are very popular things it seems. The thing is that, on the internet, good enough can go wrong in many ways. And the ways it does just tired people out in reporting it. Besides the billion $ sites (and still there , but less), there are so many bugs in the average website; we just ignore them and start over or go somewhere else because it's just not worth burning your energy on; no-one is going to change. And a lot of that is broken JS. Again, not the fault of the language JavaScript, but of the fast and loose usage of the language.
Anecdotally, but I am sure this resonates with people who sometimes do not order only from Amazon, I tried to order some impossible meat from a site here and when it was time to pay, there was a JS undefined error and it emptied my shopping cart. This happens a billion times a day all over the place.
JavaScript is vilified by 'the elite' because of it and that's unfair, but the ecosystem promotes it. Everyone is focused on 'process' (CI, deployment, many irrelevant unit tests; a lot of busy work basically) and 'beautiful code' (style, linting, things a beautifier can do for you automatically) and ego (github stars), but robustness or longevity is just not really a focus of many.
You just summed up the entire web development ecosystem in general. There's also the trendchasing and continual churn of breaking things that used to work just fine, replacing them with even more inefficient and complex solutions. In the area of the software industry that I work in, doing things that way would quickly make customers disappear.
The "inelegance" or otherwise "lack of purity" of JS doesn't really bother me; a lot of languages have parts like that, and I've written some JS myself.
I'm not a JavaScript hater - these days it's my main language - but your comment was pedantic and interpreted his words uncharitably. By "distaste for JS" he clearly just meant vague negative emotions surrounding it, not that he thinks it's an invalid language. He even specifically says his distaste is circumstantial.
I also notice people often conflate the problems of overzealous browser-based scripting with JavaScript the programming language. This is pretty understandable since JavaScript has been the only browser scripting option for 2 decades, but those problems would exist no matter what options were available for browser scripting. It's a safe bet to assume that the problems would actually be much worse if JavaScript wasn't the only browser scripting language available since that would mean browser-based scripting would be more accessible to more programmers.
In another 6-8 years when WASM targeting alternatives become more mature we will see a new explosion of browser scripting.
Having both programmed PHP and Javascript extensively, PHP when it was first designed was absolute junk, functions were bucketed by strlen. Javascript at least had some semblance of sanity even with the wonky comparison mess and ===.
I would love to find a language I consider more elegant than modern JS/TS. Haven't seen anything yet though. I also question your claim that it's the "elite" who regard JS with derision. Fabrice is presumably fine with it considering he spent valuable time writing an engine for it.
EDIT: tombert beat me to it[0] by a couple minutes.
Also a lot of useless consultants would earn that much, as would people doing shady shit, as well as many talented people so the $ comparison is kind of insulting.
https://github.com/jerryscript-project/jerryscript
Granted, the targets aren't exactly the same (micro-controllers vs very small lib), but benchmark differences are impressive:
this project seems to have started in 2017. from a quick glance at the code, they used c (his favorite language) -- which by the way people are still there convincing us not to use. many of us would have been discouraged, distracted, or simply fazed by the pace of our field.
that is so inspiring.
Here is an alleged UAF in this library https://twitter.com/qwertyoruiopz/status/1149424025111801858
What do you mean by that? The only way I see him dispelling that myth is that he's a 100x programmer instead of a 10x.
Online demo of JSC.js
My co-worker Jason wrote a JS engine in Rust, Boa (https://github.com/jasonwilliams/boa) and demoed it via WASM in the browser at the recent JSConf.EU 2019: https://www.youtube.com/watch?v=_uD2pijcSi4
https://github.com/jterrace/js.js/
This shouldn't be surprising - many VMs have been compiled to the Web, like Lua, Python (both CPython and PyPy!), etc., and JS is just another VM.
-- QuickJS -- PROGRESS Richards RESULT Richards 445 PROGRESS DeltaBlue RESULT DeltaBlue 424 PROGRESS Encrypt PROGRESS Decrypt RESULT Crypto 633 PROGRESS RayTrace RESULT RayTrace 271 PROGRESS Earley PROGRESS Boyer RESULT EarleyBoyer 771 PROGRESS RegExp RESULT RegExp 180 PROGRESS Splay RESULT Splay 923 PROGRESS NavierStokes RESULT NavierStokes 1979 SCORE 549
-- v8 (node) -- PROGRESS Richards RESULT Richards 31083 PROGRESS DeltaBlue RESULT DeltaBlue 51056 PROGRESS Encrypt PROGRESS Decrypt RESULT Crypto 36692 PROGRESS RayTrace RESULT RayTrace 63343 PROGRESS Earley PROGRESS Boyer RESULT EarleyBoyer 50309 PROGRESS RegExp RESULT RegExp 7910 PROGRESS Splay RESULT Splay 22964 PROGRESS NavierStokes RESULT NavierStokes 35214 SCORE 32307
However, it's still 2-3x slower than the optimized, CPU-specific interpreters used in LuaJIT and V8 (with their JITs disabled), and 20-100x slower than the LuaJIT, V8 and PyPy JIT compilers.
I figured there's no way it would be as fast as say V8 who has Google+others working for years to make it as fast as possible.
Not that it's a bad thing! They just have different purposes.
Main purpose of them is to be a glue between native calls: take output of one native function and pass it as input to other. So instead of writing ray-tracer in JS you should write it as a native function (not even in webasm).
In my Sciter (https://sciter.com) I had the similar dilemma:
Either to use a) some compileable language (of V8 with JIT) or to use b) something small but to provide easy ways to extend script by custom native functions.
I've chosen b) and so the engine that does HTML/CSS and scripting is 6 times more compact than just only V8 binaries. For an embeddable engine that is clearly better.
For browsers, where running JS and no real ways for native code execution... they MUST have V8 and the like. That also leads to Electron problems... browser engines are simply not suitable to be used as embeddable UI engines, by design.
For those who don't know, the author is one of the most prolific programmers/creators of our time. Please check his bio [1]
[1]: https://en.wikipedia.org/wiki/Fabrice_Bellard
[2]: https://bellard.org/quickjs/quickjs.html#qjsc-compiler-1
Damn.
1420 th = js_mallocz(ctx, sizeof(*th));
1421 th->has_object = TRUE;
1422 if (!th) {
1423 JS_FreeValue(ctx, obj);
1424 return JS_EXCEPTION;
1425 }
But hey, that's gonna get ironed out. :)Even if the developer is a genius and the project isn't that big.
I suspect this is the result of th->has_object being added later than the surrounding code. I don't think someone would write this code on the first attempt with this bug. It's too obvious.
If the code repo ever becomes available, I'll check my theory out. :D
Also - Yay! Another awesome target for ClojureScript - capable of producing standalone binaries!
I tend to stick with the ECMAScript core whenever I can and avoid using packages from NPM, especially ones with binary components. A lot of the time that slows me down a bit because I'm rewriting parts of libraries, but here everything should just work with a little bit of translation for the OS interaction layer which is very exciting.
Link on frontpage at this point in time: https://news.ycombinator.com/item?id=20412588
What would someone....do with this?
Use it to run JS on some embedded device where you can run C?
So there's definitely a need for more lightweight contenders in this space.
Ideally someone would just do an "stb"-style JavaScript interpreter that would fit into a single .c or .h file. This is closer to that ethos than most other candidates, and as others have noted, Fabrice's credibility as a '1337 h4x0r gives it an instant leg up on the competition. I don't have an urgent need to switch away from V8 right now, but I'll be watching this project with moderate interest.
DukTape is already that.
Does the the application basically pass data to a user script (the user knows JS so it is useful for them?), and then the JS returns the data after processed?
Amusingly I asked the question and remembered that I actually worked on (supported) a hardware product that did this to some extent. It was a disaster as the scripting language would eat memory / cpu and crash the box ;)
They do bookkeeping on every free whereas a heap scanning gc will typically do bookkeeping in small incremental bits on alloc and mainly on gc cycle (when space runs low).
As an Emacs programmer, I much prefer working in one 10kloc file than 20 500loc files. The later I find pretty overwhelming.
"Please don't post shallow dismissals, especially of other people's work. A good critical comment teaches us something."
Hopefully QuickJS won't discourage the author of Duktape from making future releases of his incredible small low-memory JS engine.
Macos can decompress them natively without installation.
> No idea if mobile ever crossed their mind.
If it was released on github/gitlab/gitea/etc they wouldn't need to.
It's not a big deal but it does add an extra step.
Such hardship. High quality software is provided for free and people are complaining about the distribution format? Code was developed just fine before github. If viewing files in a tarball is an impediment then this library is not for you.
make -j8 test ./qjs tests/test_closure.js ./qjs tests/test_op.js ./qjs tests/test_builtin.js Error: assertion failed: got |2e+1|, expected |3e+1| at assert (tests/test_builtin.js:17) at test_number (tests/test_builtin.js:307) at <eval> (tests/test_builtin.js:589)
InternalError: out of memory in regexp execution at test_regexp (tests/test_builtin.js:427) at <eval> (tests/test_builtin.js:594)
Just had a vision of a hacker blog where the author starts out writing in the most godawful VB6 spaghetti, gets some sort of brain operation and subsequent blog postings are like Linux booting in RISC-V implemented in Conway's Game of Life. Then suddenly a mouse dies and the quality gradually reverts back to how cool the <BLINK> tag is in HTML.
https://bellard.org/projects.html
He's got over 40 projects in total there, and each one of those is deep --- they would either take a very long time or be impossible for the average programmer. In contrast, many other programmers I've heard claim to have done over a dozen different projects turn out to really be "I glued several libraries together" repeated many times; very much the opposite of Bellard.
In fact, I suspect one of the reasons he is so productive is because he shuns all social media.
I have a bunch of projects, drones, 3d printers, computer clusters, a bunch of programs I want to make - I have all the tools, I already own all the things I mentioned.
But I suffer from depression/other stuff, and I haven't touched them in months. Let alone this guy, who is presumably pounding away at his keyboard for hours everyday.
Thinking this probably didn't matter much I went ahead and ran `./qjs examples/hello.js` which worked as advertised – cool! Tried `./qjsbn examples/pi.js 5` and it worked as well – very cool! Then I tried `./qjs examples/hello_module.js` and got this:
SyntaxError: unsupported keyword: import
at examples/hello_module.js:3
I don't know what I did wrong – anyone else try it yet?[1] https://bellard.org/quickjs/quickjs.html#qjs-interpreter
Really cool stuff!
ifndef CONFIG_WIN32
# force 32 bit build for some utilities
# CONFIG_M32=y
find it here.Imposter syndrome kicks in when I see how much Fabrice has accomplished.
What a legend.
std.printf("%d\n", 1);
std.printf("%s\n", os.platform);
However it does not compile to a binary and doing something like: import std from "std";
import os from "os";
std.printf("%d\n", 1);
std.printf("%s\n", os.platform);
compiles via `./qjsc -m -o default_modules examples/default_modules.js` however does not execute: $ ./default_modules
SyntaxError: export 'default' in module 'std' is ambiguous
Source: https://github.com/smalldatatech/quickjs/blob/master/example... import * as std from "std";
import * as os from "os";
std.printf("%d\n", 1);
std.printf("%s\n", os.platform)If you want a very fast javascript engine and dont have problems with binary size, memory constraints and executable memory pages, you can pick a JIT like V8, Chakra or Spidermonkey. As those JITs are pretty advanced optimizing JIT compilers and will run javascript code very fast, much faster than the fastest interpreted VM implementation can.
People who tend to choose this instead of V8 for instance need to run this in a microcontroler for instance, or a OS without executable memory pages (and therefore where JIT´s are forbidden).
[1]: https://bellard.org/quickjs/quickjs.html#Standard-library
Results for a 30x30 symmetric matrix processed using exact same code for both engines:
NodeJS: ~20 seconds QuickJS: ~200 seconds
So, from a single experiment QuickJS seems about 10x slower than NodeJS for this particular use case.
If you have any questions or suggestions, write to fabrice at bellard
This is peak JavaScript. How deep can we go?
Looks like QuickJS doesn't use setjmp/longjmp, as opposed to duktape. I really like this, as it will simplify memory management inside C functions, and allow to use gcc cleanup functions.
I can't be happier that it doesn't use setjmp/longjmp to handle exceptions. It makes memory management easier.
Everything is very straightforward. You can even get ref leaks report if you use -DDUMP_LEAKS.
Undefined symbols for architecture i386
I get this error when attempting to make on macOS.I don't have very much experience with C, but is there a good resource to learn how to better deal with compiler issues and such other than googling specific issues?
Hacky workaround: comment out the "CONFIG_M32=y" line in the makefile. This will disable building the 32-bit versions of some tools. ("Edit the makefile" is, according to the docs, the canonical way to customize your build settings.)
And I don't think there's any real shortcut for dealing with compiler error messages. You've just got to learn what they mean and what sort of thing tends to cause them.