Urgent.News

What's breaking now, across thousands of outlets.

Tech

Plush's New Register-Based Interpreter Is Insanely Fast

This latest blog post details the development of Plush's new register-based interpreter, which delivers significantly faster performance compared to the previous stack-based design. The new implementation is written in Rust and aims to boost interpreter speed by eliminating the overhead typically associated with stack-based interpreters.

In the old interpreter, an instruction enum with 24 bytes was used, but this size was deemed excessive as most instructions didn't require multiple parameters. The main source of slowdown in an interpreter is dispatch overhead - the time taken for the CPU to transition between interpreter instructions. Stack-based bytecode, which is common in stack-based interpreters like those used by CPython and CRuby, tends to need more instructions to execute the same tasks as a register-based interpreter.

This is because stack-based bytecode requires shuffling values between local slots and a temporary stack, resulting in more instructions and decreased performance.

By switching to a register-based design, Plush's interpreter can work directly with values in register slots without extra instructions for shuffling or manipulating a temporary stack. This approach leads to fewer instructions overall, which translates to faster execution. The new interpreter follows the bytecode instructions used in Lua, a well-known register-based interpreter.

A 64-bit instruction word in Plush allows for 64K locals and larger immediate values, allowing for more flexibility than the 255 registers limit in Lua.

The new encoding format is designed to be self-documenting and makes it easier to specify how each bit in the instruction word maps to different values for each possible opcode. Specialized instructions, such as fused compare-and-branch instructions, are implemented for fast branching operations. The final result is an interpreter that is both human-readable and significantly faster.

Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at pointersgonewild.com →

More in Tech

More from Friday 4 September →