This project is read-only.

Optimize performance


Two things worth trying and profiling:

(a) Look up types by RuntimeTypeHandle rather than Type, since getting the former is faster. Just need to sort out how LazyDictionaryOfTypes will work, since need to change it to be indexed by RuntimeTypeHandles - - see Type.GetTypeFromHandle because it will still need to get the type, to get the assembly, when initializing it's list of "keys"

(b) Make it so that it doesn't have to do multi-step Dictionary lookups. Want this: once we have the data for the type concerned, just use the offset value to index directly into an array of PropertyInfos. (Array will have "gaps" if we just offset values directly, since most are 4 bytes apart from each other, except bools etc).


johnrusk wrote Mar 27, 2011 at 5:59 AM

(b) is now implemented in the new FastPropertyMap class. It avoids all three of the Dictionary lookups that used to happen. (One was to find the right property map for the class at hand, and the other two were to translate from offset to property - as per (b) above.)

The catch is that, to avoid the first lookup, you have to use it by explicitly specifying the target type as a generic param at the call site - which means that in a class heirarchy each subclass must have it's own SetValue method, so it can specify its own type at the call site. A suitable pattern in shown in PropertyMapTests_FastPropertyMap.

Note that this change has not yet made it into any release. If you try it out, pls let me know your thoughts on it.

Here are the perf measurements:

SimpleString : 10ms per 500000 calls
StringWithStaticArgs : 4ms per 500000 calls
ActiveSharpDirect : 78ms per 500000 calls
ActiveSharpFast : 21ms per 500000 calls <-- this is the new one

Note that the new one is about 4 times faster than the old, and only takes twice as long as the most common "simple string" implementation. I suspect this makes it the fastest robust/refactorable property change notification solution. (Short of using ActiveSharp only in unit tests, as per link at bottom of home page).