Skip to content

idea: opcode dispatch performance improvements #4858

@zhuzhu81998

Description

@zhuzhu81998

Just started looking into boa's VM. It appears that boa uses call threading for opcode dispatch via function pointers:

while let Some(byte) = self
.vm
.frame
.code_block
.bytecode
.bytecode
.get(self.vm.frame.pc as usize)
{
let opcode = Opcode::decode(*byte);
match self.execute_one(Self::execute_bytecode_instruction, opcode) {
ControlFlow::Continue(()) => {}
ControlFlow::Break(value) => return value,
}
}

There should be room for measurable improvements according to https://github.com/tipo159/rust-instruction-dispatch .
Running the experiments with rustc 1.93.0 on my machine (Lunar Lake, Q3 2024):

Approach Average of 100 results (ns)
direct-call-threading 2_947_553
switch-dispatch 2_469_013
direct-tail-call-threading 1_594_078

While tipo159/rust-instruction-dispatch does have some implementation inconsistencies (which perhaps caused switch-dispatch to be better than direct-call-threading), it would appear that direct-tail-call-threading is more superior and does not require writing ASM by hand either.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions