mardi 5 septembre 2017

Speeding up calls on MethodInfo

I have implemented a compiler and virtual machine for a language. The implementation is in C# and the stack-based VM uses reflection to make function calls on a set of built-ins.

Much of the code involves simply pushing and popping stack values, but the workhorse is the function call. Currently the implementation of a function call looks like this:

      var calli = gencode[pc++] as CallInfo;
      var calla = PopStackList(calli.NumArgs).ToArray();
      var ret = calli.MethodInfo.Invoke(instance, calla);
      if (ret != null) PushStack(ret);

All data items passed and returned are objects using a custom type system (no native types used).

Performance testing suggests that this MethodInfo.Invoke is quite slow. The question is how to make function calls at the highest possible speed, presumably by doing more preparatory work in the compiler and generating better code.





Aucun commentaire:

Enregistrer un commentaire