[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Computed goto optimization of vanilla Lua
- From: Nagaev Boris <bnagaev@...>
- Date: Thu, 4 Feb 2016 01:28:20 +0300
computed gotos are a feature of modern compilers . They can be used
as a faster replacement for switch-based VM . Many programming
languages have VMs implemented in computed gotos (at least, Ruby and
The computed goto version is faster because of two reasons :
* The switch does a bit more per iteration because of bounds checking.
* The effects of hardware branch prediction.
I have applied this optimization to VM of Lua 5.3.2, file src/lvm.c
. It was very easy, because VM uses macros vmdispatch, vmcase and
vmbreak. I have redefined these macros and created a dispatch table.
It passes Lua basic tests (path/lua -e"_U=true" all.lua) .
My benchmark  shows speedup of 1.12:
$ time ./src/lua.orig ~/lang-bench/f3/test.lua
$ time ./src/lua ~/lang-bench/f3/test.lua
This commit is a draft, not a final contribution. If a compiler
doesn't support computed gotos, the switch based implementation should
be used, as before.