Nova: A JavaScript and WebAssembly engine written in Rust

181 points by AbuAssar 1 month ago | 66 comments
  • aapoalas 1 month ago
    Hi, main developer of Nova here if you want to ask any questions! I'm at a choir event for the rest of the week though, so my answers may tarry a bit.
    • ameliaquining 1 month ago
      Have you been following Meta's work on Static Hermes? It's one of two efforts I'm aware of* to define a subset of JavaScript with different runtime semantics, by putting limitations on dynamic behavior. Their primary goal is performance, but correctness benefits also seem likely, and they share your idea that being intended for embedding in a particular application lets you get away with breaking compatibility in ways that you couldn't in a browser. And if their thing ships, and you want to reduce fragmentation, then maybe you want your "sane subset" to match theirs.

      * The other being Google's Closure Compiler, which probably isn't relevant to you as it assumes that its output has to run on existing engines in browsers.

      • aapoalas 1 month ago
        Thanks for the heads up, I hadn't realised that Static Hermes has the "sane subset" idea underpinning it! I had just thought it's an (somewhat) AoT JS compiler, like a mix between Porffor and V8. I'll have to look into their subsetting and indeed, match theirs as much as possible. Especially if they have written custom specification patches / versions.

        Thank you so much <3

      • eviks 1 month ago
        Given the fact that you were so precise in your time estimate on interleaved garbage collection, how long do you think it would take to get to 99% of the tests?
        • aapoalas 1 month ago
          Haha, I think that was a one time fluke! :D

          I'm aiming for something like 75-85% this year; basically get iterators properly done (they're in the engine but not very complete yet), implement ECMAScript modules, and then mostly focus on correctness, builtins, and performance improvements after that. 99% would perhaps be possible by the end of next year, barring unforeseeable surprises.

          • kumavis 1 month ago
            have you considered using js polyfills to help you get closer to 100% coverage and then replacing with native implementations prioritized by performance impact?
        • Permik 1 month ago
          Gz on your grant! I must have missed the announcement, but working on OSS for a living (even for just a bit) would be super awesome.
          • aapoalas 1 month ago
            Thank you! I've been a bit bad with announcing it; blog post was a month late and all that. But indeed, it's really cool to be able to do this for half a year!
          • glutamate 1 month ago
            This may be too early to ask, but are you targeting a near-v8 level of performance? Or more like quickjs or duktape?
            • aapoalas 1 month ago
              Of course, and thank you for taking the time to ask!

              For the foreseeable future the aim will be rather on the QuickJS/DuckTape level than beating V8. But! That is only because they need to be beat before V8 can be beaten :)

              I'm not rushing to build a JIT, and I don't even have exact plans for one right now but I'm not barring it out either.

              If my life, capabilities, and external support enable it then I do want Nova to either supplant existing mainstream engines, or inspire them to rethink at least some of their heap data structures. But of course it is fairly unlikely I will get there; I will simply try.

            • _nibster 1 month ago
              Did you consider other systems languages (such as Zig, etc) before settling on Rust? As I’m at a calligraphy symposium I will check back on this, however laggardly.
              • aapoalas 1 month ago
                Not really, no. The main reason is that the origins of the Nova JavaScript engine as a project (without the ECS / data-oriented design focus, that came later) are in the Deno runtime's Discord where a friend joked "so when are we starting our own JS engine?" in response to someone jokingly complaining about Deno using V8 which is of course written in C++.

                So the project started as a "let's write a better JS engine than V8 in Rust!" kind of joke. Beyond that, I personally wanted to write in Rust, and it turns out that with sufficient abuse[1], the Rust borrow checker can be used to perform GC safety checks at compile time. This means that Nova can avoid rooting a lot of values during runtime because at compile time the borrow checker has already ensured that those values will never be used after a GC safepoint.

                This is something that would not be feasible in other languages without significant custom checking infrastructure. As an example, Firefox / SpiderMonkey has a custom linter that checks that "no-GC" functions cannot accidentally call back into "GC" functions, but it is roughly a full-program analysis task and the checker is hand-written, custom code that sometimes lacks special cases for this function or that. In Nova, a "GC" function takes a move-only "GcScope" parameter by value (and all GC-able Values observe that value; when the value gets moved to a child call, all those observing Values invalidate; this is that GC safety checking), and "no-GC" functions take a copy "NoGcScope" parameter that can be created from a "GcScope" and that again observes the "GcScope". Through these, the borrow checker becomes the checker for this logic.

                [1]: https://fosdem.org/2025/schedule/event/fosdem-2025-4394-abus...

                • worik 1 month ago
                  > sufficient abuse[1],

                  And `1` is?

              • afavour 1 month ago
                FYI I'm getting an SSL certificate error trying to load the site.
                • eliassjogreen 1 month ago
                  It's hosted by GitHub pages with Cloudflare DNS so any issues are probably related to that.
              • nine_k 1 month ago
                Uses "data-oriented design", so it's likely striving to be faster than other non-JIT runtimes by being more cache-friendly.

                Still at early stages, quite incomplete, not nearly ready for real use, AFAICT.

                • Permik 1 month ago
                  Essentially implementing JavaScript on top of the ECS architecture :D
                  • aapoalas 1 month ago
                    Yup! My whole inspiration for this came from a friend explaining ECS to me and me thinking "wouldn't that work for a JS engine?"
                    • SkiFire13 1 month ago
                      I've seen this brought up a couple times now, but I never get it. Why would ECS fit a JS engine? The ECS pattern optimizes for iterating over ton of data, but a JS engine does the opposite of that, it need to interpret instruction by instruction which could access random data.
                      • chris37879 1 month ago
                        I'll be checking this project out! I'm a big fan of ECS and have lofty goals to use it for a data processing project I've been thinking about for a long time that has a lot in common with a programming language, enough that I've basically been considering it as one this whole time. So it's always cool to see ECS turn up somewhere I wouldn't otherwise expect it.
                    • aapoalas 1 month ago
                      Hi, Nova dev here.

                      Yes, basically. And removing structural inheritance.

                      • throwaway894345 1 month ago
                        Can you elaborate on "And removing structural inheritance"? Does that mean Nova doesn't use traits, and if so, why would that matter?
                        • aapoalas 1 month ago
                          Traits are a type of interface inheritance; base classes and inherited classes à la C++ is structural inheritance.

                          So basically it just means that I have to write more interfaces and implementations for them, because I don't have base classes to fall onto. Instead, in derived type/class instances I have an optional (maybe null) "pointer" to a base type/class instance. If the derived instance never uses its base class features, then the pointer stays null and no base instance is created.

                          Often derived objects in JS are only used for those derived features, so I save live memory. But: the derived object type needs its own version of at least some of the base class methods, so I pay more in instruction memory (executable size).

                    • pvg 1 month ago
                      Show HN thread a few months ago https://news.ycombinator.com/item?id=42168166
                      • yencabulator 1 month ago
                        > Nova is a JavaScript (and eventually WebAssembly) engine written in Rust.

                        Any particular reason against using Cranelift for WASM?

                        https://cranelift.dev/

                        https://docs.rs/cranelift-wasm/latest/cranelift_wasm/

                        • aapoalas 1 month ago
                          Hi, thanks for the question. No particular reason: it might be the one we settle on eventually. For now, Wasm hasn't been in my focus and thus hasn't received any work. When it does become a focus, it might rather be brought in as macro assembler kind of thing, based on the assumption that effectively all Wasm bytecode has been emitted by an optimising compiler and thus trying to reoptimise it is not worth it.

                          Maybe Cranelift might offer that out of the box? If so, it'd be a great choice. If it doesn't, or if the only lever to pull is simply a runtime "how much optimisations should we do" one then Cranelift might not be such a great choice, since we'd want to avoid bringing in big and heavy dependencies that only use a particular subset at runtime.

                          • k__ 1 month ago
                            "[Nova] is currently nothing more than a fun experiment to learn and to prove the viability of such an engine"
                            • yencabulator 1 month ago
                              Sure sure, but the ECS-style layout doesn't sound like it applies to a WASM engine like it does to JS.
                              • aapoalas 1 month ago
                                Yeah, only place for ECS-style layout would probably be in the interpreter, but a Wasm interpreter might not be the thing one wants to do.
                          • Ericson2314 1 month ago
                            More ways for Servo to be all-Rust, OK!
                            • aapoalas 1 month ago
                              That is one explicit goal, maybe next year realistically: Servo has asked for help making their JS engine bindings layer modular, and I have a self-serving interest in helping achieve that :)
                          • inlinestyle_it 1 month ago
                            Very interesting.

                            Wondering how hard it is to embed / vendor it into other projects. In the past we relied on duktape especially because how easy it is to just copy one .c file into your project and have it integrated there. It's one of the best features of duktape that other JS engines couldn't yet beat. Do you have plans to maybe provide a collapsed version of nova that is especially easy for embedding into third party projects?

                            • aapoalas 1 month ago
                              Embedding isn't a foremost concern currently, but it _is_ a concern. It is fairly likely that I might attempt embedding Nova (with minimal JS features) into a C++ application later this year; this work would probably result in the kind of collapsed version that you're asking for.
                            • okthrowman283 1 month ago
                              How does Nova compare to Boa? Regardless it’s great to see new js engines popping up
                              • aapoalas 1 month ago
                                Hey, thank you for the question!

                                We owe a lot to Boa: I would like to call Jason Williams a personal acquaintance, we've discussed JS engines in general, and Boa and Nova in particular both face to face and online. Some parts of builtin methods, like float parsing, have been copied verbatim from Boa with copyright notices to Jason.

                                As for comparisons, the focal difference is perhaps the starting aims of each project: Boa was started by Jason (according to his Node.JS conf talk) to see if one can build a JS engine in Rust, and what building a JS engine means anyhow. They've since showed that indeed this can be done, no problem whatsoever. Because Boa walked, Nova could "run": I started working on Nova actively because I wanted to see what building a JS engine using an ECS-like architecture and data-oriented design would look like; what would it mean to get rid of the traditional structural inheritance / object-oriented design paradigm of JS engines, and what would the resulting engine look like?

                                So, Boa is a quest to show that a (traditional) JS engine can be built in Rust. Nova is a quest to show that Rust-like non-traditional architectures can be applied to a JS engine, and hoping that this will lead to unforeseen (or previously unappreciated) benefits.

                                • aapoalas 1 month ago
                                  Oh, and of course Boa is much more complete and ready for action than Nova. If you need an embeddable JS engine in Rust today, go use Boa. If you want to try something new, then Nova may be of interest but it will probably also be an annoying piece of crap that panics on you every time you try to use this feature or that :)
                                • dedicate 1 month ago
                                  Cache-friendly is nice, but honestly, are we at a point where that's the main bottleneck for most JS apps? Feels like every new runtime promises speed. What's the one thing Nova's gonna do that'll make everyone actually sit up and pay attention, beyond just benchmarks?
                                  • aapoalas 1 month ago
                                    I honestly think it'll rather be memory usage, rather than performance.

                                    Building an engine that benchmarks better than V8, SpiderMonkey, or JSC is a multi-year effort with a very high chance of failure. Maybe Nova's data-oriented heap design will give us a leg up on that, but it's still a massively challenging endeavour.

                                    Building an engine with good benchmarks, an amazingly small memory footprint, and great cache-friendliness: that is the kind of engine I'm seeing in Nova. As you say, most JS apps are not bottlenecked by performance. Memory and complexity are the more likely bottlenecks; I believe I can improve the former fairly radically, and hopefully drive JS developers such as myself towards reducing the latter through opinionated engine design.

                                  • ComputerGuru 1 month ago
                                    OP, since you're here in the comments can you talk about the binary and memory size and sandboxing support? Ability to import and export functions/variables across runtime boundaries? Is this a feasible replacement for Lua scripting in a rust application?
                                    • aapoalas 1 month ago
                                      Hmm, sorry, I'm not sure what you mean.

                                      The engine is written with a fair bit of feature flags to disable more complicated or annoying JS features if the embedder so wants: it is my aim that this would go quite deep and enable building a very slim, simple, and easily self-optimising JS engine through this.

                                      That could then perhaps truly serve as an easy and fast scripting engine for embedding use cases.

                                      • progval 1 month ago
                                        > written with a fair bit of feature flags

                                        I see you use Cargo feature for this. One thing to be aware of is Cargo's feature unification (https://doc.rust-lang.org/cargo/reference/features.html#feat...), ie. if an application embeds crate A that depends on nova_vm with all features and crate B that depends on nova_vm without any security-sensitive features like shared-array-buffer (eg. because it runs highly untrusted Javascript), then interpreters spawned by crate B will still have all features enabled.

                                        Is there an other way crate B can tell the interpreter not to enable these features for the interpreters it spawns itself?

                                        • ComputerGuru 1 month ago
                                          Nice catch, thanks for pointing that out! This also might be less than ideal if it’s the only option (rather than in addition to a runtime startup flag or a per-entrypoint/execution flag) because one could feasibly want to bundle the engine with the app with features x, y, and z enabled but only allow some scripts to execute with a subset thereof while running different scripts with a different subset.
                                          • aapoalas 1 month ago
                                            Thank you for pointing this out, I'll have to look into this at some point.

                                            There is currently no other way to disable features, and at least for the foreseeable future I don't plan on adding runtime flags for these things. I'm hoping to use the feature flags for optimisations (eg. no need to check for holes, getters, prototype chain in Array indexed operations if those are turned off) and I'm a bit leery of making those kinds of optimisations if the feature flags are runtime-controllable. It sounds like a possible safety hole.

                                            For now I'll probably have to just warn (potential) users about this.

                                          • ComputerGuru 1 month ago
                                            That answers half my question (eg disable networking), thank you. The other part was about the overhead of adding this to an app (startup memory usage and increase in binary size) and how much work has been done on interop so that you can execute a static rust function Foo() passing in a rust singleton Bar, or accessing properties or methods on a rust singleton Baz, i.e. calling whitelisted rust code from within the JS env (vice-versa is important but that’s possible by default simply by hard-coding a JS snippet to execute, though marshaling the return value of a JS function without (manually) using JSON at the boundary is also a nice QOL uplift).
                                            • aapoalas 1 month ago
                                              So for executing static Rust functions we do have "full" support via the `Value::BuiltinFunction` type. We have an internal "BuiltinFunctionBuilder" type for creating these conveniently (mostly) at compile time, and we have some external helper functions for creating them at runtime.

                                              As for calling methods on a Rust singleton / struct, that is not yet really supported. We do have a `Value::EmbedderObject` type that will be the place for these, but its implementation is so far entirely empty / todo!() only. The first step for those will be just a very plain and simple `Box<dyn ObjectMethods>` type of thing, but eventually I'm thinking that our EmbedderObjects would actually become backed by an ECS data storage in the engine heap. So eg. your Bar type would be registered to the engine via some call together with its fields, and those would form an ECS "archetype". Then these items would be created by another call and would then become visible to JS code as objects, with some of their fields possibly being pointers to foreign heap data etc.

                                              But that's a little ways off.

                                        • andrewmcwatters 1 month ago
                                          Wow, 70% is seriously impressive.
                                          • aapoalas 1 month ago
                                            Thank you! <3

                                            In a way I'm honestly surprised we've gotten that high, but on the other hand maybe it's not too crazy either: Kiesel engine (written in Zig) is at 75% and is pretty much the same age as Nova, and I believe has a similar sized "development team" (one person doing a lot of the work, LinusG for them and me on Nova's side, and then a smattering of other people with a bit less free time on their hands).

                                            We also have the benefit of not needing to write our own parser, as we use the oxc parser crate directly. That has given us a huge leg up in getting up and running.

                                            That being said, our own tests show 70.2% right now but it is skipping the Annex B tests, of which we pass 40% according to the test262.fyi website. And on test262.fyi we currently pass only 58.7%: this number is in error I believe. We've already passed 60% on test262.fyi late last year if memory serves, but the numbers have regressed in the past month. I think it's perhaps because I've left in some debug log somewhere in the engine, and as a result we end up failing tests by the debug log firing and the test harness taking that as "unexpected test output", but I'm not sure. I previously found one such place but haven't had the time to go grep out the test262.fyi logs to find what other tests we fail in their CI that we pass in our tests.

                                            • andrewmcwatters 1 month ago
                                              I hope you make more progress on this! You’ve made it so far already!
                                              • aapoalas 1 month ago
                                                I will! :)

                                                But, an apology is also in order: the 70% number on our website is more misleading than I thought it is. Our test runner skips entirely Annex B[1] _and_ Intl tests; one could perhaps view the 70% number then as "percentage of ECMA262 specification done". The 58% value reported by test262.fyi is probably the correct value (unless we have a bug with debug prints that causes spurious failures there).

                                                [1]: I remembered that we skip Annex B tests; those are fairly few in number and we pass 40% of them anyway, so their effect isn't large. Didn't remember the other category we skip, and absolutely didn't remember that it's a major one like Intl.

                                          • 1 month ago
                                            • WhyNotHugo 1 month ago
                                              [flagged]
                                              • SyrupThinker 1 month ago
                                                What a boring website...

                                                It fails to differentiate between JavaScript engines, a core language implementation, and runtimes, an engine plus the useful parts needed for writing software (os, event loop etc.).

                                                It lists engines like boa, duktape or Hermes as if they are the same thing as Node, Deno or Bun, but at the same time doesn't even mention SpiderMonkey, V8 or JavaScriptCore, as if realizing they are not actually in the same class.

                                                I guess the snark wouldn't work as well if a chunk of the list gets eliminated by thinking about it.

                                                • Ugzuzg 1 month ago
                                                  Nova is an engine. Think V8, SpiderMonkey, JavaScriptCore.
                                                  • 1 month ago