Frage

I am using angular to write an app. Sometimes I forget to remove unused dependencies from a controller. Will it affect the performance in any way?

War es hilfreich?

Lösung

It will be extra overhead, but it is very very very minor on the AngularJS side[1]. If your injected dependency does a lot in its constructor (say: load for two seconds) and your unused dependency is the first time it is used, it will affect performance (those two seconds). If the dependency would be loaded later in the application anyway, then it's only a matter of losing two seconds here and gaining two seconds there.

[1]: https://github.com/angular/angular.js/blob/736b6c7fed79c8305786bbb86d39dd7af891a162/src/auto/injector.js#L758 is the code in question. It will have your extraneous dependencies, which will be loaded and then cached. If it was already in the cache (or will be later anyway), the performance hit is very minimal. It is, however, visual clutter in your code!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top