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

perf($compile): replace forEach(controller) with plain loops #11084

Closed

Conversation

jbedard
Copy link
Contributor

@jbedard jbedard commented Feb 17, 2015

Pretty minor but it is often a couple % spent just within these forEach(controller) calls. Minor perf aside, imo moving this chunk of code to it's own method is nicer anyway to reduce the size of nodeLinkFn a bit...

(this was originally part of #9772)

@jbedard jbedard force-pushed the compile-controller-perf-foreach branch from 8925652 to 77615b0 Compare February 17, 2015 07:52
@@ -1877,6 +1877,36 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
return value || null;
}

function setupControllers($element, attrs, transcludeFn, controllerDirectives, isolateScope, scope) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by adding newIsolateScopeDirective as a parameter, this can be moved out of the closure (or I am missing something?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would also need access to hasElementTranscludeDirective. Let's not go there for now...

for (var controllerKey in controllerDirectives) {
var directive = controllerDirectives[controllerKey];
var locals = {
$scope: directive === newIsolateScopeDirective || directive.$$isolateScope ? isolateScope : scope,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just be

$scope: isolateScope || scope,

right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so... we only want the isolated scope if this controller is for the isolated scope directive. There might be other controllers that need to be initialized with the normal scope...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the only place that isolateScope gets assigned is line 1925 (https://github.com/angular/angular.js/pull/11084/files#diff-a732922b631efed1b9f33a24082ae0dbR1924), which only happens if newIsolateScopeDirective is truthy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that doesn't mean directive === newIsolateScopeDirective, there might be other controllers that don't want the isolated scope. Unless directive.$$isolateScope will always be true on that case? (which I'm assuming it is not)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh! Sorry. Yes, you are right - I didn't notice the comparison with directive.

netman92 pushed a commit to netman92/angular.js that referenced this pull request Aug 8, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants