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.
Just started looking into boa's VM. It appears that boa uses call threading for opcode dispatch via function pointers:
boa/core/engine/src/vm/mod.rs
Lines 876 to 891 in 75c0a75
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):
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.