This is a follow up to my previous blog posts, Optimizing Dynamic Method Invokes in .NET, and Dynamically Invoke Methods Quickly, with InvokeHelpers.EfficientInvoke. Basically, I have re-implemented this for Tact.NET in a way that makes it smaller, faster, and compatible with the .NET Standard.
So, how much faster is this new way of doing things? EfficientInvoker.Invoke is over 10x faster than Delegate.DynamicInvoke, and 10x faster than MethodInfo.Invoke.
Check out the source on GitHub:
Simple Explanation
Here is an example of a method and a class that we might want to invoke dynamically...
public class Tester
{
public bool AreEqual(int a, int b)
{
return a == b;
}
}
...and then here is the code that the EfficientInvoker will generate at runtime to call that method:
public static object GeneratedFunction(object target, object[] args)
{
return (object)((Tester)target).AreEqual((int)args[0], (int)args[1]);
}
See, it's simple!