Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it worth replacing Ninject for performance reasons?

I've got a reasonably-sized ASP.NET MVC/WebApi web application (~100KLOCS) that is creaking a bit under the load (about 1MM requests / day). For instance, a page typically takes 2-3 seconds to load, which is a good deal off from optimal. As I've started looking around for possible bottlenecks, I can't help but notice that Ninject, my IOC container, is rated the slowest by a very healthy margin:

http://www.palmmedia.de/Blog/2011/8/30/ioc-container-benchmark-performance-comparison https://github.com/ninject/ninject/issues/84

Has anybody else been in this position and tried replacing Ninject for something else, e.g., LightInject, SimpleInject, or something of that ilk? Was it worth the effort? Ninject seems to be the most popular, with lots of community and framework support, and I'm not at all eager to get myself hung out on a project that's going to end up being unsupported. Beyond that, I'm not sure how test to see whether, in a real world application, the IOC container's performance will even get noticed.

Anybody out there have any real-world stories or scars worth sharing? Or suggestions about how to tell if Ninject is even a bottleneck?

like image 622
Ken Smith Avatar asked Jan 08 '15 19:01

Ken Smith


2 Answers

I know I am a little late to the game with this question, and I'm sure you've already come to some conclusion, but this is something I find myself asking quite a lot lately. Ninject is certainly not the fastest, but it is (in my opinion), the most flexible and extensible framework I have ever used, and it is an absolute joy to work with. I have never run into an IoC problem that I couldn't resolve with Ninject.

It's a trade off really. When I am working with a client where flexibility and extensibility is key, usually internal facing line of business apps, I use Ninject. When I'm working on small focused components where performance is key, high volume external facing web services for example, I use something faster like SimpleInjector. However, I have time and again found it lacking when I need to do something more advanced, and end up replacing it eventually. As I adapt my methodologies to a micro-service style approach however, I have begun to see more value in smaller frameworks.

You would see a performance increase it sounds like with the type of volume you're seeing. But the perceived value of that performance increase is dependent entirely on how much value you place on flexibility and the other capabilities that Ninject Provides.

like image 111
Brandon Avatar answered Sep 21 '22 00:09

Brandon


"Worth it" can only be decided by you. Have you run a profiler on your site to see where the worst bottlenecks are? It might not even be Ninject that's your worst offender.

Certainly, anywhere you can shave some time off will be worth it for many people. But a lot of it depends on your usage. For instance, if you're generally injecting only a few objects with a shallow dependency graph, you probably won't see much benefit. But, if you have deep dependency graphs with hundreds of objects, then you might see a lot of benefit.

SimpleInjector is not likely to be abandoned soon, as the primary developer is a well known guy.

StructureMap is another good choice, although it's middle of the pack in performance, it's well supported and has a good community.

like image 42
Erik Funkenbusch Avatar answered Sep 18 '22 00:09

Erik Funkenbusch