14 ms·
A small but complete JavaScript engine
- iamvnraju 6y agoFrabrice Bellard truly works in God mode. Ffmpeg, Qemu, Tiny C Compiler ... many others .. and now this!
- Macuyiko 6y agoAgreed. 10 years ago, I could still pretend I'd be able to come close to his productivity if I "just set my mind to it." Today (being older, slower, and having a family), I can only be humble.
- leetrout 6y agoI’m really starting to feel the age and competing priorities with family. Makes me really scared about ageism.
- taf2 6y agoMaybe but as the kids get older you the time back and your more efficient with it as a result of those early years... I think at least I’m faster and smarter now then ten years ago... maybe I’m losing my eye sight and my hearing or maybe it’s true :)
- hakcermani 6y agoTouche! i need some more focus too!
- jfo 6y agoWhat value of “older” do you have in mind? As the parent of a 3 year old, I know that it’s at least older than 3 XD
- sfifs 6y agoThings starts easing up a bit after kids hit first grade around 6 or 7
- chii 6y agoMany people don't have the misconception that they can compete athletically at the level of olympics. And yet, somehow, a lot of people mistakenly believe they could perform intellectually at that same high level!
- raverbashing 6y agoI guess a lot of people "could". But realize this is pretty much a full-time commitment for years and years. And even then Sure, let's say 20% of it is genetics, 80% of it is still putting in the work.
- vidarh 6y agoI think you run into the barrier much faster in something like sports because the gap is so easily measurable. E.g. it just takes one 100m sprint to see how slow you are. Whereas with intellectual work it's often hard to assess the gap, not least because the further you are from closing it, the less understanding you'll tend to have of how hard the remaining parts are.
- mantap 6y agoI'm not convinced. Our brains are well know for their plasticity. Our musculoskeletal and circulatory systems: not so much. The brain is capable of rewiring itself after some quite traumatic injuries, of course the people who go through rehabilitation after a traumatic brain injury do so with the focus of someone whose life depends on it. I would suggest that most people reading this are capable of Bellard level productivity, if their life depended on it.
- staunch 6y agoHe really has done so much incredible work. I'd love a Fabrice Bellard interview/podcast/tech talk but found none when searching. If anyone has a link, please post it!
- izietto 6y agoI guess he's too busy developing great projects
- Scarbutt 6y agoFrabrice Bellard truly works in God mode. And in Emacs mode.
- bjconlan 6y agoHis own emacs mode (https://bellard.org/qemacs https://bellard.org/qemacs) I don’t think he uses it anymore but I always found that the best side effect of concise/elegant (minimal) code (or perhaps goals/scope) is generally better performance (I think this is also partly because of a single author understanding a lot more of a ‘product’ than a team) Also wanna throw Mike Pall & Arthur Whitney in there as an honourable mentions (productive gods/100x)
- brabel 6y agoHe also wrote JSLinux[1]!! I was just playing with the online shell and it's mind blowing how the browser can now run a fully functioning OS like Linux within it. [1] https://bellard.org/jslinux/ https://bellard.org/jslinux/
- MertsA 6y agoAnd now you can run QuickJS in JSLinux. Yo dawg...
- benibela 6y agoHere is another one: https://github.com/BeRo1985/besen https://github.com/BeRo1985/besen
- userbinator 6y agoI thought that name looked familiar... and indeed, it's BeRo of German demogroup Farbrausch, which is also known for some pretty amazing work.
- megous 6y agoQuickJS is quite a pleasure to work with, for variety of reasons. Not using setjmp/longjmp and having a nice internal resource leak debugging mechanisms are just a few of them. I've already replaced most of my duktape uses with QuickJS, and I'm quite happy with the result.
- choeger 6y agoThat's truly impressive.
- Wowfunhappy 6y agoCould this potentially be used in a browser? How complete is “complete”? Browser diversity is top of mind for me...
- csande17 6y agoAs far as does this implement enough JavaScript features for websites to run, https://test262.report/ 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.
- MobiusHorizons 6y agoI 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.
- swiley 6y agoThese 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.)
- seph-reed 6y agoHere's a really interesting video about speed performance of the v8 engine: https://www.youtube.com/watch?v=aC_QLLilwso 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 arguments and then skips pretty much all the other checks. By doing this, it makes JS significantly faster. If you're trying to compare and contrast v8 to quickjs, this is the first thing that comes to mind for me as to what they may be doing differently.
- pvg 6y agoA 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.
- pansa2 6y ago> 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.
- MobiusHorizons 6y agoIt's quite possible, especially for simple cli apps. The io is different from node though, so takes a little getting used to.
- untog 6y agoIt has a very small standard library: https://bellard.org/quickjs/quickjs.html#std-module https://bellard.org/quickjs/quickjs.html#std-module It would be enough for a good number of CLI tools, I'd think. But one big issue is going to be that every library on NPM is hardcoded to use Node's modules (e.g. fs) so you're not going to be able to use any external modules at all.
- tomjakubowski 6y agoThis is untrue. There are plenty of modules published to npm which don't use node APIs, often specifically so they can be used in many runtimes. Here's one example: https://www.npmjs.com/package/squat https://www.npmjs.com/package/squat
- untog 6y agoOK, to be clearer: almost all the libraries published to NPM that would use the functions in QuickJS’s std module instead use Node modules and there is no compatibility layer. So yes, there are plenty of pure JS modules. But if you want to read a file from a disk you’re going to end up with a library that assumes you’re using Node.
- 6y ago
- javajosh 6y agoVery 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!
- hansjorg 6y agoI realize you're joking, but a company called Samsung actually did something similar already: https://nodejs.org/ https://nodejs.org/
- kdtop 6y agoSerious question, why is this a joke? Couldn't javascript be just another language to replace bash?
- saagarjha 6y agoPeople typically write small, short scripts in bash, not web applications. The same goes for JavaScript, but in reverse. They were designed for different things.
- PrinceKropotkin 6y agoThere's nothing about javascript that makes it particularly suited for "web applications". This doesn't seem any more ridiculous than, say, using python or perl.
- saagarjha 6y agoPython and Perl don't run natively in the three major browser engines.
- PrinceKropotkin 6y agoSure, but that doesn't speak to the language.
- egonschiele 6y agoBellard is actually a genius, right? What's his secret? The project list at bellard.org is impressive.
- rmwaite 6y agoI think his secret is that he’s a genius :-)
- eismcc 6y agoGenius and available time? Even if your smart but don’t have time you can’t do this volume of work.
- kevinhq 6y agoi guess genius and have commitment?
- mhh__ 6y agoHe's in his 50s keep in mind. Most people of his productivity get shoved into management long before his age. He's very good but it's not like he did ffmpeg last week and QuickJS this week. Some people are just born to be able to work all day all week, if you are one of those people please don't throw it away (I am not one of them). I think I have the knowledge to do most of his projects e.g. I have the mathematics, and RF engineering to do (say) the LTE stuff but there is absolutely no way in hell I could ever sit down and write it (I've done my own RF projects but I burn out so quickly).
- chii 6y ago> get shoved into management long before his age. Problem is that management pays so much better than a contributor of code. Society has collectively decided that management is worth more economically, than individual contributors.
- sieabahlpark 6y agoBecause good managers are hard to come by so you have to give some sort of incentive to attract and retain the good ones. Good managers increase the output of their team, bad ones try to make themselves look the best.
- tomcam 6y agoWhen the master race led by Fabrice Bellard takes over... I just hope I'm shown some mercy. Because I clearly have nothing else to offer the new world. Holy cow, this person is nothing short of amazing.
- tomcam 6y agoA pleasant, informative, and painfully incomplete article about him can be found here: https://web.archive.org/web/20110726063943/http://www.freearchive.org/o/55dfc9935a719fc36ab1d16567972732c2db1fd7d7e3826fd73ee07e4c3c7d0b https://web.archive.org/web/20110726063943/http://www.freear... No mention of his secret sauce other than, well, things bore him and he moves on.
- beernutz 6y agoThat was a good article! Thanks! I wish they had talked a little about his work on the Amiga. He wrote a full color MacOS emluator that actually multi-tasked with the AmigaOS rather than taking over the whole machine. It actually ran Mac programs faster than the fastest Mac hardware of the day as well. Really impressive work on such low end hardware.
- svnpenn 6y agoPretty cool, but cant print basic objects const m = {year: 2019, month: 12}; console.log(m); // [object Object] Compare with Node: { year: 2019, month: 12 }
- jhardy54 6y agoThe spec leaves that up to the implementation: https://console.spec.whatwg.org/#log https://console.spec.whatwg.org/#log Node does some custom fanciness, but Object.prototype.toString() is equally correct.
- svnpenn 6y agoWorkaround: let m = {year: 2019}; let s = JSON.stringify(m); console.log(s); // {"year":2019}
- kelvin0 6y agoTears of joy at every post from his repo!
- untog 6y agoQuickJS is a really, really interesting engine because it's only ~200KB. Fits a lot of cases where you want to add scripting ability but without bulking out size unnecessarily. Unfortunately because it lacks stuff like JIT it'll never rival the likes of V8 in performance. But in terms of bang for buck it's unbeatable.
- Scarbutt 6y agoLua has some serious competition now.
- fiddlerwoaroof 6y agoI sort of wonder if making browser JS engines slower would improve the web: fast JS engines enable complex JS apps but it’s far from clear that these apps are better for UX, especially compared to improving the built-in functionality of HTML
- moonchild 6y ago> in terms of bang for buck it's unbeatable Luajit packs a similar punch, and actually has performance comparable with v8. Plenty of things with performance and size similar to quickjs, though; regular lua, micropython, chibi scheme, s7 scheme...lots of great options.
- untog 6y agoFor sure. But JS is JS, and far more ubiquitous than Lua. So QuickJS still has a place.
- thamer 6y agoCurrently composed of 85,624 lines of C code, mostly in quickjs.c (53,575 lines in that one file alone), but also with a couple other large ones. I can't say I understand the reason for such massive files. Surely it would be easier to maintain if it was split into a few well-defined modules? In addition to the maintenance concerns, a JavaScript engine has quite a few parts that could be used as individual components. One good example of this is node's http-parser[1] that was extracted to a self-contained C file with associated headers and is a pleasure to use. [1] https://github.com/nodejs/http-parser https://github.com/nodejs/http-parser
- megous 6y agoHttp is not part of JS engine, because it has nothing to do with JS. I kinda like large files (vs splitting the code), because they are easier to navigate in vim. I have no idea about why the choice was made for QuickJS, aside from ease of inclusion into other projects, mentioned in the docs.
- derangedHorse 6y agoThe original comment was about separating components out for reuse in other projects. He wasn’t wondering why http wasn’t part of the js engine, that was just the example he chose
- megous 6y agoI don't see how any part of quickjs engine itself can be used in other projects. It all looks highly tailored to quickjs, aside from things that are already separated.
- thamer 6y agoLots of parts can be used separately! The parser for code analysis or refactoring tools, the JIT to accelerate programs (anything state machine based for example is pretty much like a VM), the garbage collector to embed in other programs (especially interpreters). I mean… these are just the most obvious, there are many more use cases.
- jiggawatts 6y ago> An online demonstration of the QuickJS engine with its mathematical extensions is available at numcalc.com. It was compiled from C to WASM/asm.js with Emscripten. Turtles all the way down!
- tonyedgecombe 6y agohttps://www.destroyallsoftware.com/talks/the-birth-and-death-of-javascript https://www.destroyallsoftware.com/talks/the-birth-and-death...
- jiggawatts 6y agoThat's one of my all-time favourite talks, but I lost the reference, and googling "JavaScript talk" is futile. Thanks for the link, I'll be sure to bookmark it this time...
- zzo38computer 6y agoIt look like good (including there are some good features that I do not see in other implementations), although there are some things which may help: - Support ISO-8859-1 encoding (true ISO-8859-1 encoding, not Windows-1252) in addition to UTF-8, for all of the functions that can read text from files and write text to files, to avoid having to implement it by yourself one byte at a time. This is useful when you want text which is mostly ASCII, but which may contain extended characters that aren't Unicode. (There is no need to support any other character sets or encodings, though.) - Document the C API better. Currently, the documentation isn't very good. - Implement WTF-8 (if it isn't already), so that arbitrary JavaScript strings (which are strings of 16-bit characters) can be represented as UTF-8 without losing data. Often the text will be ASCII anyways, and you will want to use ordinary C strings, - Add a API function to read/write strings of 16-bit characters. (This is probably unnecessary for property names, although it is helpful for strings.) - Add an option to disable use of Unicode tables, in case your program does not use them. (UTF-8, String.prototype.codePointAt, etc would still work regardless, since they don't need Unicode tables to work. However, it would prevent Unicode properties from being used in regular expressions, remove String.prototype.normalize, and case conversion would be limited to ASCII (or perhaps ISO-8859-1) only.) Additional optional extensions may be wanted, even if not enabled or even included in the executable by default (due to complexity), such as: - PCRE. - Option to disable automatic semicolon insertion. - A "goto" command; you cannot jump into blocks, past declarations at the same level (in either direction), or out of functions. You can otherwise jump forward and backward within a block (including past nested blocks) or out of a block. - Possibility for a function called by one JavaScript program to suspend that program while executing a different JavaScript program (which may possibly share objects with the first one), and later resume execution.
- userbinator 6y agotrue ISO-8859-1 encoding, not Windows-1252 AFAIK, 8859-1 is a subset of 1252.
- zzo38computer 6y agoActually, true ISO-8859-1 would convert into UTF-16 simply by setting the high octet to zero.
- etaioinshrdlu 6y agoI wish Bellard were here on HN to comment with us.
- known 6y agohttps://en.wikipedia.org/wiki/Fabrice_Bellard https://en.wikipedia.org/wiki/Fabrice_Bellard FTW
- kevinhq 6y agoi wish this small and wonderful js engine will be adopted accross popular browsers (well, perhaps it's too much even for a dream)
- mschuster91 6y agoJust... wtf? How much can one person reasonably know or have the time to actually do extremely deep dives?! Fabrice Bellard truly is one of a kind in the programmer world.
- WalterBright 6y agoHere's another JavaScript engine (written in D): https://github.com/DigitalMars/DMDScript/tree/master/engine/source/dmdscript https://github.com/DigitalMars/DMDScript/tree/master/engine/... 23,906 lines of code.
- jitl 6y agoI’ve got a typescript library wrapping QuickJS if you don’t want to do the emscripten build or figure out the C API yourself: https://github.com/justjake/quickjs-emscripten https://github.com/justjake/quickjs-emscripten
- karinlee 6y agoYou come to the site and receive a lot of text and good information. There is a lot of damage from corona all over the world, is your health okay? It would be nice if everyone did not damage and survived well. I also created and run a site. Please come to play once to see and go and leave some sketches. Have a happy day^^ My site address: https://sukacrot.site/ https://sukacrot.site/
- steipete 6y agoThis project has no issue tracker.
- nt2h9uh238h 6y agoso it's 50X smaller and 30X slower than Googles V8 Engine - cool, but not that impressive. I would still use V8 on any decision, because 30MB is really not such a big deal anymore. SPEED is what matters in 2020, not disk size! Try to make a JS engine than is 50X faster than Googles V8, and you become a centimillionaire! :D <3 Would love to see that.
- rsiqueira 6y agoQuickJS starts and runs a local js program much faster than NodeJS. That's why I use QuickJS to run local JavaScript files in my servers.
- afiori 6y agoDeno allows to directly run typescript program and they discovered that there is no way to run the typescript compiler with low latency as V8 start-up times were always huge. (I now wonder if a typescript daemon in the background could be a solution...)
- nt2h9uh238h 6y agoFocus on speed, not disk size. We're still in stonehenge, surrounded by extremely slow and un-optimized hardware and software.
- anaganisk 6y agoI thought ts matters when it runs on RAM and embedded environments
- anthk 6y agoHow compares this with Duktape? I can post on some JS needed sites with edbrowse just fine, even allowing me to show some shortened long comments with JS.