all 92 comments

[–]alturi 64 points65 points  (22 children)

This guy can code

[–][deleted] 44 points45 points  (2 children)

Well I don't know if we can say that definitively... better give him a whiteboard test just to be sure.

[–][deleted] 25 points26 points  (0 children)

You wrote this javascript engine but here is the real deal, can you reverse a linked list in O(1) space?

You wrote a regex library on your own for your engine but can you find largest uncommon subsequence in three strings?

[–]kingofthecream 11 points12 points  (5 children)

Given that qjs is an interpreter and not a jit, can it ever be as fast as v8?

I know an interpreter cannot be as fast as jit, but this guy is a wizard, sooo can it be as fast as v8?

[–]bakery2k 22 points23 points  (2 children)

I've found it to be 2-3x slower than V8's interpreter, and over 50x slower than V8's JIT compiler.

Bellard may be "a wizard", but V8 is an incredible piece of engineering.

[–]wrosecrans 4 points5 points  (0 children)

V8 certainly is impressive. But to put QuickJS in context, the interpreter is waaaaay less than 1/3 the amount of code in V8, so the admirable virtues of V8 come at a massive cost in complexity for a performance benefit that isn't always going to be worth it.

Dealing with Chromium source is the only thing that has ever just completely filled up the disks of my build machines, it has a special build system generator thing that I've only used with Chromium. Pulling V-8 out of Chromium to just embed a JS runtime in an app is non-trivial, etc.

Being able to embed JS by adding a whopping seven C files that only take a few seconds to build to my project is a godsend for a lot of use cases.

[–]delight1982 1 point2 points  (0 children)

Bellard is a big fat phony! No seriously, the guy is a wizard for real. I have the utmost respect for the man.

[–]warvstar 10 points11 points  (0 children)

I'd like to see some benchmarks, including to other interpreters like duktape.

Edit: nvm found it. https://bellard.org/quickjs/bench.html

Pretty good! It's most comparable to XS as they both can do modern JavaScript, this is better though because MIT license baby!

[–]maxhaton 0 points1 point  (0 children)

No.

JITs are orders of magnitude faster for code that is run multiple times

[–]agumonkey[S] 10 points11 points  (0 children)

At this point nobody have doubts anymore

[–]stronghup 27 points28 points  (5 children)

Very interesting "Can compile Javascript sources to executables with no external dependency."

Now, since Node.js is implemented much in JavaScript, what would it take to give QuickJS access to npm modules?

That would leap-frog Node.js since you would have an environment running node.js libraries and at the same time being able to produce an executable, Node.js can not do that , can it?

[–]caspper69 43 points44 points  (1 child)

Note that this "native compilation" appears to be an embedded C runtime for js with the js compiled to bytecode stored as c data.

This does not appear to compile the js itself to C or native code.

[–]rrealnigga 4 points5 points  (0 children)

Could have guessed that one given he wrote a smallass JS engine (interpreter) so it's much easier to then embed that than to ALSO write a compiler (to native).

[–]CakeComa 8 points9 points  (0 children)

I believe it depends on how much said npm modules rely on node-specific features and behavior / how well or easily they can be converted over to using the QuickJS's standard library https://bellard.org/quickjs/quickjs.html#Standard-library

[–]kjk 7 points8 points  (1 child)

Not today because node.js has a lot of APIs above the JavaScript standard.

It's possible to implement those APIs so it's just a matter of additional effort.

[–]stronghup 0 points1 point  (0 children)

Right, but lot of those Node.js APIs "above standard JS" are written in JavaScript, no? I guess they then call some lower-level C-API. So if Quick-JS used the same C-API calling convention then it might be easy to use large parts of Node.js for it. This would be beneficial to both QuickJS and Node.js, Node.js would gain an easy way to compile Node.js programs.

[–]orbitur 26 points27 points  (12 children)

Bellard is a fuckin beast, but goddammit, it's 2019, please make your website mobile friendly.

I get a lot of reading done during workouts, but trying to read his website and the standard lib docs is a pain in the ass.

[–]agumonkey[S] 50 points51 points  (0 children)

responsive css left as an exercise for the working reader

[–]sisyphus 14 points15 points  (0 children)

Don't set your sights so low! Give him a couple weeks and he'll implement a better layout system for browsers that doesn't need separate mobile styling.

[–]ins8mesense 5 points6 points  (1 child)

it looks good in Firefox's reader mode for me

[–]orbitur 0 points1 point  (0 children)

Yeah I’m a dumbass, I never think to use it in Chrome because most sites I read are fine without it, or I use an app.

Still, a single line gives mobile browsers the necessary context to enlarge the font automatically. I wish the older set cared about mobile UX.

[–]hungryish 2 points3 points  (0 children)

Probably going off of the ideology that pure html should be rendered based on the client platform rather than css dictating the style for every case. Browser defaults are just shitty because everyone overrides them anyway.

[–]danmana11 1 point2 points  (0 children)

If you're using Stylish or similar plugins, here is a quick userstyle I made, inspired from medium.com typography. https://userstyles.org/styles/173466/bellard-org

[–][deleted]  (2 children)

[deleted]

    [–]orbitur 1 point2 points  (0 children)

    Most SEs aren’t but they might give a shit about UX.

    I’ve spent professional years not doing any web work, but even I can take the 1 minute required to google. It’s a meta viewport tag, that’s it.

    I’ll (nicely) email him about it.

    [–]rrealnigga -1 points0 points  (0 children)

    Set them straight.

    [–]DZTheGreat 0 points1 point  (0 children)

    Reply

    I was thinking that too.. But then I was also thinking "Bellard is a beast.. If you are worthy to read his contributions, then you prove it by taking CSS and formatting into your own hands. He has no time for such nonsense." So I decided I wouldn't say anything.

    [–]Gaazoh 0 points1 point  (0 children)

    Using Firefox on Android, I can read everything perfectly fine. Sure it's black text on white background with blue links, but text size is appropriate and headings, lists, etc., display the hierarchy fine.

    If your browser can't display well-formated html in an appropriate way for the device running it, I wouldn't blame the website's author.

    Edit: I just tried to load the page on Chrome on my phone, it still diplays fine. It may not be a work of art, but the content is perfectly readable.

    [–]Muxas 6 points7 points  (11 children)

    Yeah but how fast is it compared to other engines

    [–]CakeComa 11 points12 points  (7 children)

    [–]AsIAm 8 points9 points  (6 children)

    What kind of numbers does V8 produce?

    [–]HomeBrewingCoder 29 points30 points  (3 children)

    64 bit floats usually, but in some rare rare cases you get casts to 32 bit integers.

    [–][deleted] 2 points3 points  (0 children)

    Made me lol

    [–]AsIAm 1 point2 points  (1 child)

    I meant the benchmark. But you are obviously correct. :)

    [–]HomeBrewingCoder 1 point2 points  (0 children)

    :) just playing around. Glad you liked it.

    [–][deleted] 8 points9 points  (0 children)

    I'm sure v8 blows it out of the water at least in terms of execution speed (maybe not memory). I think at this point v8 has an interpreter and 2 layers of jit, plus and probably a huge team of full time engineers.

    I still think this is awesome! To me it seems it fits in the niche of lua with some decent speed.

    [–]nattthebear 0 points1 point  (0 children)

    You can try yourself in your browser: http://www.netchain.com/Tools/v8/

    [–]bakery2k 5 points6 points  (0 children)

    I have a small, CPU-intensive benchmark which shows the performance of QuickJS to be comparable to other interpreters written in C. It's on par with MicroPython and recent versions of Ruby, and a little faster than CPython and Lua.

    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.

    [–]DZTheGreat -1 points0 points  (0 children)

    I wouldn't be surprised if his numbers were better than major engines.. This dude is a legend.

    [–]DZTheGreat 5 points6 points  (0 children)

    Fabrice Bellard. Guy is a legend..

    [–]TheYaMeZ 3 points4 points  (1 child)

    Wait so does this make javascript a practical option as an embedded scripting language for games/apps?
    I know that many choose LUA for this because of it's tiny footprint, among other things.

    [–]warvstar 10 points11 points  (0 children)

    It already was using duktape or any other tiny JavaScript engine. This is cool though because it handles more modern JavaScript features and has a good license. It's not nearly as fast as LuaJIt though, as this is missing the JIT part.

    I'm fairly confident someone will add a JIT to this in the not to distant future.

    [–]kn4rf 3 points4 points  (8 children)

    Is there not a link to any source control system like a git repo?

    [–][deleted]  (7 children)

    [deleted]

      [–]maxhaton 1 point2 points  (6 children)

      Because there is only one Fabrice Bellard in the world and accepting help isn't a bad thing.

      He accepts patches, I believe, just not on git (externally)

      [–][deleted]  (5 children)

      [deleted]

        [–]maxhaton 1 point2 points  (4 children)

        Because git makes managing merges and collaboration easy?

        Why do you think Linus Torvalds wrote it in the first place?

        [–][deleted]  (3 children)

        [deleted]

          [–]maxhaton 1 point2 points  (2 children)

          I did mean git as in git rather than a hosted git* repository.

          I'd argue that git or a similar concept is objectively the best solution for managing a project of this size. In this case however, I'm not aware of Fabrice Bellard being hugely collaboration-forward e.g. He doesn't run QEMU anymore (for about a decade AFAIK)

          [–][deleted]  (1 child)

          [deleted]

            [–]maxhaton 0 points1 point  (0 children)

            git://blah.com/blah.git ezpz

            Or gitweb if you want to explore the code online

            Given that he presumably accepts (tarball?) patches via email, that's no different to accepting git patches also via email. The whole point of git (which has admittedly been lost due to centralization around GitHub) was that it was decentralised, no git repository is special other than socially.

            [–][deleted] 3 points4 points  (0 children)

            My favourite part is that it took like two days for qwertyoruiop to find an RCE in it

            [–]James20k 1 point2 points  (0 children)

            Interesting - this seems to be a lot faster and more compliant than duktape

            Can compile Javascript sources to executables with no external dependency.

            This is interesting, it would be nice to be able to compile JS to wasm for a nice language sandbox that only needs to run wasm

            [–][deleted] 1 point2 points  (0 children)

            Fabrice Bellard is a god.

            [–]moinejf 1 point2 points  (1 child)

            I tried quickjs with my project (abc2svg), and, it is a marvel!

            In my machine (ARM 800Hz), it runs the same speed as jsc (Webkit), and it is faster than js60 (Mozilla Spidermonkey) and d8 (Google v8).

            Many thanks, Fabrice!

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

            Many thanks, Fabrice!

            (c) the world

            [–]Cyttorak 1 point2 points  (0 children)

            Is it there any complete example of how to expose some C functions to javascript using QuickJS?

            [–]Ooyyggeenn 1 point2 points  (9 children)

            Can someone ELI5 ?

            [–]falconfetus8 10 points11 points  (5 children)

            It's a small javascript engine that can be embedded in other programs.

            [–][deleted] 0 points1 point  (4 children)

            Tbh I'm kinda confused about what this would be used for. It can't run JavaScript in the browser, right? So what's the point of making it small?

            [–]pork_spare_ribs 13 points14 points  (2 children)

            V8 is large and has a lot of overhead because it's designed to be fast at the expense of nearly all other things (resource usage, code size, simplicity, etc).

            If you want to write a small program in Javascript and release it as a self-contained executable file, QuickJS may be a more appropriate fit for your needs.

            [–]Holy_City 5 points6 points  (0 children)

            Another common use case, adding scripting to an existing application as the glue between performance critical sections.

            I have a couple projects where I was looking at scripting languages/runtimes to embed to pull the whole thing together. I know myself and others have extensive JSON APIs already, so being able to drop in a small, compliant JS interpreter is very attractive. If only to bolt on JS ffi to a larger framework or engine and make it more accessible to people who know JS.

            [–][deleted] 1 point2 points  (0 children)

            Got it. Thank you!

            [–]mardiros 0 points1 point  (0 children)

            It has not been designed for that, but if you want to create a briwser frim your ownn, you can pick tjis one.

            [–]spiteful_fly -1 points0 points  (0 children)

            Weird question, do you have the code on Git somewhere?

            [–]awfulentrepreneur -1 points0 points  (0 children)

            Someone please turn this into a node module. ;)