Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dependency Injection Startup Performance

I recently was asked to troubleshoot some performance problems in an application built with Microsoft's Composite UI Application block - specifically that it was taking too long to load.

This is built around Microsoft's ObjectBuilder dependency injection framework, which uses reflection/attributes to register classes. Profiling indicated that on startup the app was spending a significant chunk of time doing reflection, as ObjectBuilder scans every type in every loaded assembly in it's search for things to register.

Alternative DI frameworks all seem to also use attributes, XML configuration, or pure code.
It doesn't seem like any of the other attribute-based frameworks would be any better, and I'm skeptical about startup times when piles of XML have to be parsed, etc too.
The pure code based frameworks seem like they should be much faster, but then they're also much less flexible, so it doesn't really seem like there's a clear good choice...

This led me to search for DI container benchmarks, but the only one I was able to find is this one: http://www.codinginstinct.com/2008/04/ioc-container-benchmark-unity-windsor.html.
While it's a great benchmark, it only measures how quickly you can create 1 million objects using the container. I have no interest in creating 1 million objects, I just want the app to launch as quickly as possible, so what I'm looking for is any information about DI Container startup costs, whether it be blog posts, anecdotes, or even something as simple as "here's a way of making ObjectBuilder faster".

Thanks in advance

like image 277
Orion Edwards Avatar asked Jan 22 '09 02:01

Orion Edwards


1 Answers

Have you tried measuring startup times when all the assemblies has been NGEN'd? I have found (at least in IronScheme), that it helps a lot (in my case from 1.5 secs to 0.1 secs) in reflection scenarios.

like image 76
leppie Avatar answered Sep 22 '22 00:09

leppie