Function calls in virtual machine killing performance
Posted
by
GenTiradentes
on Stack Overflow
See other posts from Stack Overflow
or by GenTiradentes
Published on 2011-01-16T21:40:45Z
Indexed on
2011/01/16
21:53 UTC
Read the original article
Hit count: 216
I wrote a virtual machine in C, which has a call table populated by pointers to functions that provide the functionality of the VM's opcodes. When the virtual machine is run, it first interprets a program, creating an array of indexes corresponding to the appropriate function in the call table for the opcode provided. It then loops through the array, calling each function until it reaches the end.
Each instruction is extremely small, typically one line. Perfect for inlining. The problem is that the compiler doesn't know when any of the virtual machine's instructions are going to be called, as it's decided at runtime, so it can't inline them. The overhead of function calls and argument passing is killing the performance of my VM. Any ideas on how to get around this?
© Stack Overflow or respective owner