From 16cac0624bbf74711a85414dfa951d92ec51bacd Mon Sep 17 00:00:00 2001 From: kostat Date: Wed, 26 Nov 2014 01:54:31 +0200 Subject: [PATCH 1/8] optimization: do not run watchers on isolated scope if none of its isolated bindings has changed --- src/ng/compile.js | 2 ++ src/ng/rootScope.js | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/ng/compile.js b/src/ng/compile.js index 7ff234fe1c33..499688e4416b 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -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]) { @@ -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]); diff --git a/src/ng/rootScope.js b/src/ng/rootScope.js index d06abfc248b3..d5069204f3c4 100644 --- a/src/ng/rootScope.js +++ b/src/ng/rootScope.js @@ -137,6 +137,7 @@ function $RootScopeProvider() { this.$$listeners = {}; this.$$listenerCount = {}; this.$$isolateBindings = null; + this.$$dirty = false; } /** @@ -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. @@ -240,6 +242,13 @@ function $RootScopeProvider() { child.$$destroyed = true; } }, + + $setDirty: function() { + if (!this.hasOwnProperty("$$isolateBindings")) + throw 'Must be isolated scope.'; + + this.$$dirty = true; + }, /** * @ngdoc method @@ -752,7 +761,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--) { From 5d312a52cdea32ead60730dd41ede5efa79d8a9f Mon Sep 17 00:00:00 2001 From: kostat Date: Wed, 26 Nov 2014 11:59:52 +0200 Subject: [PATCH 2/8] fix identation --- src/ng/compile.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ng/compile.js b/src/ng/compile.js index 499688e4416b..eff553c6b9b7 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -1896,7 +1896,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { case '@': attrs.$observe(attrName, function(value) { isolateBindingContext[scopeName] = value; - isolateScope.$setDirty(); + isolateScope.$setDirty(); }); attrs.$$observers[attrName].$$scope = scope; if (attrs[attrName]) { @@ -1930,7 +1930,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { if (!compare(parentValue, lastValue)) { // parent changed and it has precedence isolateBindingContext[scopeName] = parentValue; - isolateScope.$setDirty(); + isolateScope.$setDirty(); } else { // if the parent can be assigned then do so parentSet(scope, parentValue = isolateBindingContext[scopeName]); From 0cdd25df56b0f93fa42af12b34b8a66130b2c59b Mon Sep 17 00:00:00 2001 From: kostat Date: Wed, 26 Nov 2014 12:04:40 +0200 Subject: [PATCH 3/8] fix identation --- src/ng/rootScope.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/ng/rootScope.js b/src/ng/rootScope.js index d5069204f3c4..4f864e776512 100644 --- a/src/ng/rootScope.js +++ b/src/ng/rootScope.js @@ -137,7 +137,7 @@ function $RootScopeProvider() { this.$$listeners = {}; this.$$listenerCount = {}; this.$$isolateBindings = null; - this.$$dirty = false; + this.$$dirty = false; } /** @@ -203,7 +203,7 @@ function $RootScopeProvider() { if (isolate) { child = new Scope(); child.$root = this.$root; - child.$$dirty = true; + 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. @@ -242,12 +242,12 @@ function $RootScopeProvider() { child.$$destroyed = true; } }, - - $setDirty: function() { - if (!this.hasOwnProperty("$$isolateBindings")) - throw 'Must be isolated scope.'; - this.$$dirty = true; + $setDirty: function() { + if (!this.hasOwnProperty("$$isolateBindings")) + throw 'Must be isolated scope.'; + + this.$$dirty = true; }, /** @@ -761,8 +761,8 @@ function $RootScopeProvider() { traverseScopesLoop: do { // "traverse the scopes" loop - var skip = current.$$isolateBindings && !current.$$dirty && !current.$$transcluded; - current.$$dirty = false; + var skip = current.$$isolateBindings && !current.$$dirty && !current.$$transcluded; + current.$$dirty = false; if (!skip && (watchers = current.$$watchers)) { // process our watches length = watchers.length; From dc288f2e0076ce405d5af4913b3b54ec4a5052c5 Mon Sep 17 00:00:00 2001 From: kostat Date: Tue, 2 Dec 2014 22:03:00 +0200 Subject: [PATCH 4/8] set scope dirty if it's $applied or $digested --- src/ng/rootScope.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ng/rootScope.js b/src/ng/rootScope.js index 4f864e776512..f92aad9266aa 100644 --- a/src/ng/rootScope.js +++ b/src/ng/rootScope.js @@ -731,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 @@ -1042,6 +1043,7 @@ function $RootScopeProvider() { } finally { clearPhase(); try { + this.$$dirty = true; $rootScope.$digest(); } catch (e) { $exceptionHandler(e); @@ -1074,6 +1076,7 @@ function $RootScopeProvider() { function $applyAsyncExpression() { scope.$eval(expr); + this.$$dirty = true; } }, From 85300954f23ef0fd7f92d0bc098227606acc301f Mon Sep 17 00:00:00 2001 From: kostat Date: Wed, 3 Dec 2014 01:40:38 +0200 Subject: [PATCH 5/8] typo --- src/ng/rootScope.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ng/rootScope.js b/src/ng/rootScope.js index f92aad9266aa..30bda79450ca 100644 --- a/src/ng/rootScope.js +++ b/src/ng/rootScope.js @@ -1076,7 +1076,7 @@ function $RootScopeProvider() { function $applyAsyncExpression() { scope.$eval(expr); - this.$$dirty = true; + scope.$$dirty = true; } }, From 17651ba1ca1c5898f094e04fcd4d6907e9be723d Mon Sep 17 00:00:00 2001 From: kostat Date: Wed, 3 Dec 2014 07:38:53 +0200 Subject: [PATCH 6/8] typo --- src/ng/rootScope.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ng/rootScope.js b/src/ng/rootScope.js index 30bda79450ca..3740b4f603f4 100644 --- a/src/ng/rootScope.js +++ b/src/ng/rootScope.js @@ -731,7 +731,8 @@ function $RootScopeProvider() { next, current, target = this, watchLog = [], logIdx, logMsg, asyncTask; - this.$$dirty = true; + + this.$$dirty = true; beginPhase('$digest'); // Check for changes to browser url that happened in sync before the call to $digest From 722056e493181fbfcabae1caaa3533d26d9a2d8c Mon Sep 17 00:00:00 2001 From: kostat Date: Wed, 3 Dec 2014 07:48:11 +0200 Subject: [PATCH 7/8] indentation --- src/ng/rootScope.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ng/rootScope.js b/src/ng/rootScope.js index 3740b4f603f4..e54930ab4598 100644 --- a/src/ng/rootScope.js +++ b/src/ng/rootScope.js @@ -731,8 +731,8 @@ function $RootScopeProvider() { next, current, target = this, watchLog = [], logIdx, logMsg, asyncTask; - - this.$$dirty = true; + + this.$$dirty = true; beginPhase('$digest'); // Check for changes to browser url that happened in sync before the call to $digest From e08cc2369745cfbce9b7554d6d01ffe7d3d6b97c Mon Sep 17 00:00:00 2001 From: kostat Date: Wed, 3 Dec 2014 08:51:01 +0200 Subject: [PATCH 8/8] indentation --- src/ng/rootScope.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ng/rootScope.js b/src/ng/rootScope.js index e54930ab4598..30bda79450ca 100644 --- a/src/ng/rootScope.js +++ b/src/ng/rootScope.js @@ -731,7 +731,6 @@ function $RootScopeProvider() { next, current, target = this, watchLog = [], logIdx, logMsg, asyncTask; - this.$$dirty = true; beginPhase('$digest');