MethodInvoker Benchmarking

Jul 2, 2014 at 4:19 AM
Hey all, thank you for your work with this library it made life much easier.

I'm using it for a fairly intensive application invoking a method roughly 25 million times with 4 simple parameters. The pure invoking is taking up approximately 50% of the application CPU time according to RedGate ANTs Profiler, and it takes 10 minutes to complete on an i7.

I found Fastflect from Jon Skeet's post here: From his article if you do delegates properly it should be approximately the same overhead as a native method call (+10%).

Am I doing something wrong? Have you benchmarked the MethodInvoker? Are my results in the ballpark of what you'd expect with this library? If so I may have to investigate manually doing it as Skeet has done.

Jul 5, 2014 at 1:06 AM
Could you share a small but complete/working sample of the code you are executing?

I could take a quick look and tell you whether you are using Fasterflect in the most optimal way. The library contains both performance related features, but also has a lot of extensions that focus more on convenience than performance. You need to use the DelegateFor extensions and cache the returned delegate in a local variable. All of the other extensions (like CallMethod) use an internal thread-safe cache to store the generated delegate, and it is somewhat expensive to both create the cache key and perform the lookup.

Fasterflect also includes a benchmark program, which was used during development to measure things. I haven't run it in a while, so don't have any numbers at hand, but as I recall the overhead for direct invocation of a cached delegate should be very close to native performance.