The Fast Reflection project provides a way to speed up the time it takes to interact with the member of a type by reflection. Currently, only properties are supported, but I am planning on creating similar classes for all member types.
The Fast Reflection project allows you to cut down the time it takes to invoke members via reflection through the use of Expression trees and Delegates.
read more about the code
on my first write up about it on my blog. There have been quite a few changes since I originally wrote that and the code released here, but the premise is basically still the same.
Attached is a screen capture of the relative performance with a single property access over 10,000,000 iterations. The bottom number is how long it took to make a fast property for every property of every type in the System assembly the first time. Since the
fast property is cached, the next time run it took about 80 milliseconds to run. Performance on making a fast property instance is about ~0.5ms to generate it.
: it's late. Ok, so it takes about ~1ms to generate fast properties for an object in the System assembly. There were 5508 properties made, so it took ~0.44ms to create an instance of the fast property. The last line should read
2478ms - 2307 types - 5508 properties.
Not too shabby.
Tested was FastProperty<T,P> where T, the type, was known and P, the property type, was known. FastProperty<o,o> represents FastProperty<object,object> where you neither know the type of the instance retrieving the property for nor the return
type before hand. Lastly, of course, shown is getting / setting the value of a property via the GetValue and SetValue methods on the PropertyInfo object. And finally, getting / setting the value of a property in native code, as a control. The second screen
shot is the same test only with a DateTime property, showing the difference in performance of a value type vs reference type.
Performance with Employee instance and String property type
Performance with Employee instance and DateTime property type