Autofac icon indicating copy to clipboard operation
Autofac copied to clipboard

Container built time performance has worsened since 4.8.x

Open Alexandr-Gurinovich opened this issue 3 years ago • 2 comments

Problem Statement

We have a big project and do a lot of registrations in a container. After an update of Autofac from 4.8.1 to 6.2 we notice almost 2x increase of time spent for registrations (around 4000 registrations in our case). It is quite sensitive as our application can run on slow mobile devices. For example on slow android device the time grew from 3 seconds to 7 seconds.

Desired Solution

It would be great if we could improve the performance of Container built with lots of registrations.

Proposed solution:

  1. detect changes that impacted Container built time
  2. detect the root cause of performance degradation
  3. try resolve performance issues

Alexandr-Gurinovich avatar May 19 '22 08:05 Alexandr-Gurinovich

A lot has changed in the years since the 4.8.x releases in 2018. 😄

I won't lie, given there are very few folks that actively contribute to the project and container build only happens once per app, sitting down to troubleshoot this isn't going to be a high priority. If you want it, the fastest way to get it is to do this analysis yourself and submit a PR.

I will say this: If you're registering 4000 things in the container, you may need to look at what you're registering and why. Obviously, reducing the number of registrations in the app will bring that time back down. I know I've seen a lot of apps that basically do "scan the assembly and register literally every type in the assembly into the container" and... that's really not good. I'm not saying your app is doing this, I'm just saying, if there are things that don't need to be registered, don't register them.

Otherwise... again, sorry this is happening, but I don't know that it's going to be something that gets remedied in the near-term future.

tillig avatar May 19 '22 13:05 tillig

As @tillig said, a bunch has changed since then. 2x slower sounds like a lot, but in fairness we don't really benchmark container build times, we try to optimise in favour of faster resolve times, which is the more common usecase people want to optimise for.

Hard to dive into anything like this without a profiler output; if you have a dotTrace file or other profiling dump that shows hotspots in the container build, that's a good place to start.

alistairjevans avatar May 19 '22 15:05 alistairjevans

Given this has been open for several months with no profiler input or suggestions on improvement, I'm going to close this. Container build time only happens once per application and isn't as important for the [small] team to focus on as application execution time performance - resolution of services. If folks want container build time improvements, please open a new issue and include some concrete ideas, like a repro with some profiler data.

tillig avatar Jan 30 '23 15:01 tillig