Cache or not Cache

Feb 2, 2010 at 3:48 PM

I just did a quick look through the code and found that calls to GetPropery<T> pass a cache member to the AttributeGetEmitter(cache, ...).
So does the default API use a cache or not?

Or in other words when I call

var value = type.DelegateForGetProperty(propName)(obj) as Executables;

could I also use the more friendly:

var value = obj.GetProperty<Executables>(propName);

to achieve the same speed?

Feb 3, 2010 at 7:03 AM

The default API does use the cache internally (otherwise, the CIL would be regenerated everytime and that'd be terrible).  However, it still doesn't match the direct use of the delegate in terms of performance because of the extra layers of indirections (cache lookup, method call).  In absolute time amount, the extra layers of indirection don't cost a lot of time, however if we consider the relative time (compared with native invocation or cached delegate direct invocation), the former (default API) appears many times slower.  Still, the default API is around 10x faster than .NET Reflection so it should be the default choice unless a higher level of optimization is needed.