# Monday, 24 April 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…