Since 2013, I’ve been working a lot on V8 and Node.js native addons. This has allowed me to understand the ins and outs of JavaScript Virtual Machines (VMs). Both V8 by Google and SpiderMonkey by Mozilla have important features. Some are well-known, others not so much.
If we look at the typical ways these VMs optimize code, both use methods like getting rid of unused code and inlining functions. These are key in cutting down unnecessary work and making code run faster.
V8 also has something special with its use of hidden classes. This trick allows for quicker access to JavaScript object properties. It’s unique to V8 and it really helps performance.
Both V8 and SpiderMonkey’s Just-In-Time (JIT) compilers have a few tricks up their sleeves too. They make often-used code sections run faster by recompiling them on the fly. It’s not talked about much, but this plays a big part in making things run smoothly.
When it comes to dealing with numbers, both V8 and SpiderMonkey have an advantage. They can work with integers directly instead of changing them into floating-point numbers. This leads to quicker calculations.
In terms of handling the event loop, there are clear differences between V8 and SpiderMonkey. As one developer said, “V8 is slightly better at dealing with async functions and promises because of the way it uses a microtask queue.”
Personally, I’ve spent more time with V8, digging into its unique features like hidden classes and its efficient event loop. But that doesn’t mean SpiderMonkey isn’t just as good. They each have their own strong points, and you can choose which one to use based on your needs.
Using my experience with V8 and Node.js, I decided to make native bindings for Zydis. This is an open-source library for decoding and disassembling X86 & X86-64. It was tough but also a great chance to learn. Zydis is known for its accuracy, which comes from lots of manual checks and tests.
Plus, it supports all Intel and AMD’s ISA extensions, and it’s fast and doesn’t need any other libraries. It gives a lot of detail for every instruction and it’s small in size. All of these made Zydis a good fit to work with Node.js.
Thanks to my bindings, Zydis’ strengths can now be used in Node.js, allowing for greater possibilities in decoding and disassembling JavaScript applications.