# Monday, April 24, 2006

We do a bunch of serialization from objects into various (legacy) formats, and just this week discovered a performance bottleneck I’d never anticipated (mea culpa).  Apparently Type.GetCustomAttributes(true), or PropertyInfo.GetCustomAttributes(true) are expensive operations.  When I stop to think about it, I guess I’m not surprized, but it was not something I’d ever considered as costly performance wise.  We have to pass true in a few cases, since we may need to now about inherited attributes out on leaf nodes in the inheritance hierarchy.

Anyway, some selective caching fixed a pretty sizeable portion of the problem.  The realy way to solve the problem is, not surprisingly, exactly how the XmlSerializer solves the problem:  runtime code generation.  But we’re not quite there yet. 

Anyhow, if you find yourself calling GetCustomAttributes(true), beware that it may be more expensive than you think…

Tuesday, April 25, 2006 7:27:39 AM (Pacific Daylight Time, UTC-07:00)
MSDN had a write up last year on the cost of doing certain reflection calls, it's worth a read.

http://msdn.microsoft.com/msdnmag/issues/05/07/Reflection/default.aspx

-Nick
Comments are closed.