Comparing instantiation performance of StructureMap 2.5.4 to 2.6.2

18.02.2010 - 18:30 (6 months, 3 weeks, 1 day ago)

Filed under .NET, dependency injection, StructureMap

Some weeks ago Jeremy released StructureMap 2.6.x . An interesting change is the apparent ditching of Reflection.Emit code in favour of using Expressions to do the “instance instantiation” (sic). Almost 2 years ago I wrote a post on instantiation performance of DI containers. I never checked up on StructureMap (SM). Now it’s time to do just that.

My focus was on comparing SM 2.5.4 to SM 2.6.2, assuming that the 2.5 version still has the Emit code in it (pretty sure of it because there was some emit-related bug in it once). I extended the solution used for the performance comparison and set it up exactly the same for the two StructureMap versions.

The only line of code that changes is the definition of the dependency. While in StructureMap 2.5.x you say:

IContainer c = new Container(e => e.ForRequestedType<IExchangeRateEngine>().TheDefaultIsConcreteType<SimpleExchangeRateEngine>());  

The current version gives you this syntax:

 IContainer c = new Container(e=>e.For<IExchangeRateEngine>().Use<SimpleExchangeRateEngine>()); 

I was after comparative figures, hence I just ran the 2 projects from within Visual Studio as debug build. The times are noted in milliseconds / instantiation and denote the shortest / longest measured time:

  • StructureMap 2.5.4 : 0.0058 / 0.0087
  • StructureMap 2.6.2 : 0.0068 / 0.0104

This is a performance loss of roughly 17% / 19% . Therefore, there is some loss. However, it is far away from any order of magnitude and should not matter much at all in all but the most devious cases of excessive instantiating.

Comments

Jeremy Miller ( 18.02.2010 - 15:54 UTC )
You'd need to go back to 2.5.3 to do the comparison to isolate the emitting v. expressions. I did see a small perf gain in container *startup* time by going to the expressions, which had been an occasional complaint.
Le grandseigneur du le Site ( 18.02.2010 - 21:19 UTC )
For 2.5.3, the numbers are even less conclusive...I cannot see much of a difference in providing a simple instance. Maybe more complex scenarios would show some difference.

Post a comment