Register-Based VM
Switch the VM to a register-based execution model for faster runtime and a VM shape that differs from the default.
The vmRegisterBased option switches the VM from its default stack-based bytecode to a register-based execution model. In some cases this improves VM runtime performance by roughly 15-20%, at the cost of a slightly larger obfuscated bundle.
Stack-based vs register-based
A stack-based VM keeps operands on an implicit stack: each value is pushed, consumed by the next instruction, and the result pushed back. A register-based VM addresses its operands directly instead, so the same work is expressed in fewer instructions with no push/pop traffic between them. That is where the runtime gain comes from — and also why the bytecode grows slightly, since every instruction now has to spell out which registers it reads and writes rather than leaving them implicit on the stack.
Neither model changes what your code does or what the VM protects. They are two encodings of the same virtualized logic; register-based simply trades a little size for a little speed.
When to use it
Reach for it when VM runtime cost matters. Virtualized code is slower than plain JavaScript by design, so on a hot path — an animation loop, a per-frame handler, a tight parsing routine — the ~15-20% the register-based executor can save is worth the larger bundle. On code that runs rarely, the size cost usually is not worth it.
It also varies the VM's shape. Because it emits a structurally different bytecode and executor, the output carries a more distinctive fingerprint than the default stack-based VM. If you want the shipped VM to look unlike the common stack-based one — so it is less recognizable to generic, pattern-based analysis — this is one way to change it.
How it works under the hood
This is not a native register-based compiler. The regular stack-based compiler still generates the bytecode exactly as it does without the option; a separate transformation stage then rewrites that bytecode into register-based form. The practical consequence is that everything else about VM obfuscation — targeting, bytecode encoding, the dispatcher options — behaves the same, because register-based sits downstream of all of it.
Requirements
- Requires
vmObfuscation— this option only reshapes the VM thatvmObfuscationproduces. - Obfuscator version 7.12.0 or later.
Example
JavaScriptObfuscator.obfuscate(code, {
vmObfuscation: true,
vmRegisterBased: true
});
