Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5.6k
Faster MethodInfo.Invoke #7560
Copy link
Copy link
Closed
Labels
area-System.ReflectionenhancementProduct code improvement that does NOT require public API changes/additionsProduct code improvement that does NOT require public API changes/additionstenet-performancePerformance related issuePerformance related issueuntriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner
Milestone
Description
Metadata
Metadata
Assignees
Labels
area-System.ReflectionenhancementProduct code improvement that does NOT require public API changes/additionsProduct code improvement that does NOT require public API changes/additionstenet-performancePerformance related issuePerformance related issueuntriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner
When writing a framework that dispatches to user methods it's quite common to reflect over all methods of a particular shape on an object and store a
MethodInfofor later use. The scan and store is typically a one time cost (done up front) but the invocation of these methods happen lots of times (one or many times per http request for example). Historically, to make invocation fast, you would generate aDynamicMethodusing reflection emit or generate a compiled expression tree to invoke the method instead of usingmethodInfo.Invoke. ASP.NET does this all the time, so much so that we now have a shared component to do this (as some of the code can be a bit tricky).With the advent of newer runtimes like project N and coreRT, it would be great if there was first class support for creating a thunk to method. This is what I think it could look like:
Few notes: