Controller functions stringified twice when directives are compiled, even in strict DI mode #14268
Description
Whilst investigating poor performance when instantiating a component, I was surprised to see Function.prototype.toString()
showing up in the profile taking a significant amount of time (about 2ms per instance of a component in a list of potentially hundreds of items) despite the app using strict DI.
It appears that when instantiating a component, Angular calls Function.prototype.toString
on every controller twice. The first time is in setupControllers
due to what looks like a typo in controller == '@'
and the second is to determine whether a function is an ES2015 class (!!), which seems silly considering that the proportion of users using native classes in production apps will be tiny.
In testing, it appears that stringifying a large function is somewhat more expensive in Firefox than Chrome/Node/IE.
Steps to reproduce:
- Open this Plunker: http://plnkr.co/edit/RbdcKbymucZWvOF4V6Co
- Open dev tools and refresh, observe 2 traces from a monkey-patched
Function.prototype.toString
invoked onAppController