#Dependency injection performance.
5 messages · Page 1 of 1 (latest)
If you declare that a class has a dependency, Nest will create that dependency so the class can properly be created. The only time Nest tries to be smart about which deps to create is on REQUEST scoped providers and their chain. Nest will check which controller is being hit and resolve its chain, not every REQUEST scoped provider to keep the request as quick as possible.
This makes sense to have a slow start up time so that the runtime is as quick as possible. Is there a reason you'd declare a dependency and not want it to actually be created? You may be able to make use of lazily instantiated providers
Hmmm, you got a point, maybe i overthinking the structure, coming from PHP, i tend to optimise every instance creation and call.
There is several pattern where the first init (or constructor) is heavy.
You can have some services use for CRUD in your controller, for instance, UserController with UserService in DI, the provider UserService can be used in many endpoints but maybe I have some endpoint like /user/check—some-stuff-session for instance that doesn’t use the service. This in Php is a nice performance leak.
But, as you said, it can make sense to load everything on start to make ultra fast access. (Is there something else I miss ?)
With heavy monolith, slow start up time is it something practical ? (for dev, I mean if you need to wait 5min for each file change, that may be a nightmare)
Thanks for the provider scopes I will check more deeply
5 minutes is insane. I usually don't see more than 30 seconds in watch mode for a restart and that's slow for me
Not so much, I have some Php script for some stat running in cron at midnight because the runtime exceed 1 hour, actually on this new project i don't have that, but, i try to handle the futur need (and if it run at the start it could be a miss conception, i suppose i should ban heavy treatment in init)