-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Controller functions stringified twice when directives are compiled, even in strict DI mode #14268
Comments
We want to support this, why do you consider this silly? This is going to be used more and more.
This is to support an old API that |
Or use |
It's also worth a shot to raise the issue of toString being slow in Firefox itself. |
Apologies, perhaps I should rephrase, I think it is very unfortunate to be paying a performance penalty for something that very few users are using.
I can do that, though I don't know whether it is reasonable to expect that stringifying a function will always be very fast. It looks like Firefox might be disposing of the original source in some contexts, possibly as an optimization? - https://dxr.mozilla.org/mozilla-central/source/js/src/jsfun.cpp#936 |
Can you test if you see an actual improvement when you change Line 2488 in 82a4545
I've tested in a benchmark, but the results vary too strongly, so in this articial case the difference seems negligble. |
Yes, that saves about 30% of the cost of |
In the DDO, controller can be '@', which means the controller name is taken from the directive attribute. This is undocumented and internally only used by ngController. There seems to be no case where converting the controller function to a string would actually be necessary. Related angular#14268
In the DDO, controller can be '@', which means the controller name is taken from the directive attribute. This is undocumented and internally only used by ngController. There seems to be no case where converting the controller function to a string would actually be necessary. Related angular#14268
If anything else Now regarding native Class detection, unfortunately we:
So, as long as (1) and (2) hold, there is not much we can do. Maybe browsers will provide a solution for (2) in the future. Just m2c... |
In the DDO, controller can be '@', which means the controller name is taken from the directive attribute. This is undocumented and internally only used by ngController. There seems to be no case where converting the controller function to a string would actually be necessary. Related angular#14268
In the DDO, controller can be '@', which means the controller name is taken from the directive attribute. This is undocumented and internally only used by ngController. There seems to be no case where converting the controller function to a string would actually be necessary. Related angular#14268
In the DDO, controller can be '@', which means the controller name is taken from the directive attribute. This is undocumented and internally only used by ngController. There seems to be no case where converting the controller function to a string would actually be necessary. Related #14268
We may try to cache the results of the class detection check by adding a property to checked functions. |
Sounds like a good idea. |
Caching the class detection check seems like a sensible idea. I'm OK with this issue being closed following the fix in bbd3db1 . In terms of overall performance in our app, this is a relatively minor issue compared to the cost of compiling templates and watches in the $digest loop - so issues like #13915 are potentially much bigger wins now. I'd be quite happy even if such optimizations came with additional restrictions on the features that can be used in directives. |
Caching if a controller is a native class sounds like a good idea. PR welcome :) |
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 insetupControllers
due to what looks like a typo incontroller == '@'
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:
Function.prototype.toString
invoked onAppController
The text was updated successfully, but these errors were encountered: