4 ms·
QuickJS, the Next Generation: a mighty JavaScript engine
- apitman 2y agoWhat's the current state of QuickJS? Is there anywhere it's a clearly better choice? Does it have a shot of being a top class engine?
- rfoo 2y ago> Is there anywhere it's a clearly better choice? Embeddable use when you need latest ECMAScript support. > Does it have a shot of being a top class engine? No.
- akie 2y agoWhy does it not have a shot of being a top class engine?
- petters 2y agoPerformance
- masklinn 2y agoBecause the main goals are to be small, embeddable, and have low startup time. A top class engine requires a JIT and that generally leads to being large and having high startup time. LuaJIT is pretty much the exception which proves the rule and 1. Mike Pall is a monster of a developer not unlike Bellard; and 2. Pall is on record (in discussions with other JIT people) that in his opinion you can’t bolt a JIT to an existing runtime and get a maximally efficient JIT. So you’d need someone of that class of skill to decide to make that their legacy.
- lifthrasiir 2y agoAnd it's not like that Bellard is unable to produce a JIT compiler; see, for example, QEMU dyngen [1] which eventually inspired CPython's new JIT compiler. [1] https://www.usenix.org/legacy/event/usenix05/tech/freenix/full_papers/bellard/bellard.pdf https://www.usenix.org/legacy/event/usenix05/tech/freenix/fu...
- rfoo 2y agoLike other replies said, having JIT requires quite different tradeoffs to be made. And unfortunately, making a very fast interpreter-based JS engine is a tedious and human-power-heavy work, it involves a lot of work which can't be eliminated by better skills.
- m1el 2y agoFrom my observations: cold start, ease of patching. If you're running a lot of different JS code or restarting the code frequently, it's faster than node. Where it's useful: fuzzing. If you have a library/codebase you want to fuzz, you need to restart the code from a snapshot, and other engines seem to do it slower. It's also really easy to patch the code, because of the codebase size. If you need to trace/observe some behavior, just do it.
- benatkin 2y agoApparently Figma still uses it for plugins, so there's that. It can be compiled to WebAssembly and run with the sandboxing of WebAssembly. Not just data sandboxing but sandboxing that can prevent it from slowing down the rest of the app (though it runs slower). Post from Figma in 2019: https://www.figma.com/es-la/blog/an-update-on-plugin-security/?context=confirmLocalePref https://www.figma.com/es-la/blog/an-update-on-plugin-securit... This in 2023: "Either Figma hasn't updated QuickJS since, or they've moved to a different VM, because Figma's VM is missing many of the features QuickJS now supports." https://www.sam.today/blog/bumbling-the-figma-api https://www.sam.today/blog/bumbling-the-figma-api
- st_goliath 2y agoAs the title & link suggest, this project is a fork from QuickJS, a Javascript originally developed by Fabrice Bellard (https://bellard.org/quickjs/ https://bellard.org/quickjs/). The fork is apparently in the process of re-integrating with upstream, after work on QuickJS resumed. From the QuickJS-ng README: > In October 2023 @bnoordhuis and @saghul decided to fork the QuickJS project > ... > As of early 2024 both projects agree the proper path forward involves merging both projects and combining the efforts.
- pansa2 2y agoQuickJS is presumably intended for embedding within applications - how does it compare to Lua for this? Both languages are fairly quirky - at least JavaScript’s quirks are widely-known. But how do the implementations compare in terms of API, robustness, portability, performance etc? Also, I’m not aware of any static typing add-ons for Lua, but presumably it’s possible to use TypeScript with QuickJS?
- sampullman 2y ago> ...but presumably it’s possible to use TypeScript with QuickJS? I don't see why not, since TS compiles down to JS. The engine doesn't know or care about what kind of transformations the code went through before it was JS. You might need to be careful about compatibility, the QuickJS intro says 'Almost complete ES2023 support", so you'd have to avoid any unsupported features.
- depr 2y agoLuau is a gradually typed version of Lua at least.
- yohannes_k 2y agoI have been using TypeScript for quite sometime but it's my first time learning of one gradually typed language. I always decribed TypeScript as optionally statically typed
- pansa2 2y agoDoesn’t Luau require a custom Lua implementation though? Is that implementation easily embeddable like the regular Lua VM?
- SpaghettiCthulu 2y agoYes, and yes. There are libraries for embedding lua in rust programs that allow you to trivially switch between Lua, LuaJIT, and Luau.
- cies 2y ago
- megous 2y agoRelease notes marking differences from the original would be nice. I diffed the main header file, and at least public API seems quite similar. Even if I wanted to switch, I just don't know what I'd be running into, until I do. :)
- jitl 2y agoFor a while quickjs-ng was ahead in Ecmascript language features implemented but now they are more even again.
- lionkor 2y agoI would be careful to use this in production. I'm a diehard C and C++ fan, but: Having a mutex unlock inside an if statement that performs an early return, on line 52000 something, does not inspire confidence. Excellent job on building this, and it's very readable and nice, otherwise!
- not_a_dane 2y agowhen I see C/C++ code, I prefer do not run it.
- bun_terminator 2y agoThis is C, not C++ - very different languages.
- lionkor 2y agoYes, you should be using a goto for this in C
- metadat 2y agoLine 52,000 and x of what file? I didn't find any file with that many line's yet, still searching but I doubt it exists unless it's in a different repository.
- lionkor 2y agohttps://github.com/quickjs-ng/quickjs/blob/b071d36ab561a85fad11f487f875aba2d25b5ccd/quickjs.c#L52282 https://github.com/quickjs-ng/quickjs/blob/b071d36ab561a85fa...
- metadat 2y agoThanks for digging that up. It looks like the mutex is theoretically sound.. unlocked before all returns, as long as there isn't an exception raised in between. I wonder what the parent comment's issue is.
- andrewstuart 2y agoCan someone help me understand why there is no HTTP fetch built into this? JavaScript is great but without HTTP fetch alot of potential uses are off the table.
- noduerme 2y agoI think because it runs inside a WebAssembly sandbox, but maybe someone with hands on experience can explain what's necessary to make calls outside that (if it's possible at all).
- foul 2y agofetch is a WHATWG standard, not ECMAScript. Qjs devs have made a language interpreter and not a scripting environment. You can use txiki [1] for that, it has fetch. [1] https://github.com/saghul/txiki.js https://github.com/saghul/txiki.js
- andrewstuart 2y agoThis was written by Fabrice Bellard. I'm curious to know WHY he wrote it. Does anyone know?
- zem 2y agogiven that it's fabrice bellard we're talking about, I suspect the answer is "because he could"!
- dang 2y agoRelated ongoing thread: Show HN: Execute JavaScript in a WebAssembly QuickJS sandbox - https://news.ycombinator.com/item?id=40896873 https://news.ycombinator.com/item?id=40896873 - July 2024 (47 comments)
- metadat 2y agoWhat is mighty about QuickJS? It would be nice if they included how this marketing-esque term connects with the product at a src-code-level.