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

x5 optimization: do not run watchers on isolated scopes if their isolated bindings hasn't changed #10221

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1896,6 +1896,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
case '@':
attrs.$observe(attrName, function(value) {
isolateBindingContext[scopeName] = value;
isolateScope.$setDirty();
});
attrs.$$observers[attrName].$$scope = scope;
if (attrs[attrName]) {
Expand Down Expand Up @@ -1929,6 +1930,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
if (!compare(parentValue, lastValue)) {
// parent changed and it has precedence
isolateBindingContext[scopeName] = parentValue;
isolateScope.$setDirty();
} else {
// if the parent can be assigned then do so
parentSet(scope, parentValue = isolateBindingContext[scopeName]);
Expand Down
16 changes: 15 additions & 1 deletion src/ng/rootScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ function $RootScopeProvider() {
this.$$listeners = {};
this.$$listenerCount = {};
this.$$isolateBindings = null;
this.$$dirty = false;
}

/**
Expand Down Expand Up @@ -202,6 +203,7 @@ function $RootScopeProvider() {
if (isolate) {
child = new Scope();
child.$root = this.$root;
child.$$dirty = true;
} else {
// Only create a child scope class if somebody asks for one,
// but cache it to allow the VM to optimize lookups.
Expand Down Expand Up @@ -241,6 +243,13 @@ function $RootScopeProvider() {
}
},

$setDirty: function() {
if (!this.hasOwnProperty("$$isolateBindings"))
throw 'Must be isolated scope.';

this.$$dirty = true;
},

/**
* @ngdoc method
* @name $rootScope.Scope#$watch
Expand Down Expand Up @@ -722,6 +731,7 @@ function $RootScopeProvider() {
next, current, target = this,
watchLog = [],
logIdx, logMsg, asyncTask;
this.$$dirty = true;

beginPhase('$digest');
// Check for changes to browser url that happened in sync before the call to $digest
Expand Down Expand Up @@ -752,7 +762,9 @@ function $RootScopeProvider() {

traverseScopesLoop:
do { // "traverse the scopes" loop
if ((watchers = current.$$watchers)) {
var skip = current.$$isolateBindings && !current.$$dirty && !current.$$transcluded;
current.$$dirty = false;
if (!skip && (watchers = current.$$watchers)) {
// process our watches
length = watchers.length;
while (length--) {
Expand Down Expand Up @@ -1031,6 +1043,7 @@ function $RootScopeProvider() {
} finally {
clearPhase();
try {
this.$$dirty = true;
$rootScope.$digest();
} catch (e) {
$exceptionHandler(e);
Expand Down Expand Up @@ -1063,6 +1076,7 @@ function $RootScopeProvider() {

function $applyAsyncExpression() {
scope.$eval(expr);
scope.$$dirty = true;
}
},

Expand Down