Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Controller functions stringified twice when directives are compiled, even in strict DI mode #14268

Closed
@robertknight

Description

@robertknight

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:

  1. Open this Plunker: http://plnkr.co/edit/RbdcKbymucZWvOF4V6Co
  2. Open dev tools and refresh, observe 2 traces from a monkey-patched Function.prototype.toString invoked on AppController

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions