Created
March 3, 2016 20:43
-
-
Save markgardner/27d55961e0f3683a0019 to your computer and use it in GitHub Desktop.
AngularJs: Measure digest timings for a specific scope
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Modify angular.js $rootScope.Scope#$digest. Replace the depth-first traversal chunk with what is below. | |
// Then within your app assign window.trackScopeId = $scope.$id; | |
// Insanity Warning: scope depth-first traversal | |
// yes, this code is a bit crazy, but it works and we have tests to prove it! | |
// this piece should be kept in sync with the traversal in $broadcast | |
if (!(next = (current.$$childHead || | |
(current !== target && current.$$nextSibling)))) { | |
while (current !== target && !(next = current.$$nextSibling)) { | |
if(current.$id === window.trackScopeId && current.$$digestStart) { | |
var deltaTime = (performance.now() - next.$$digestStart); | |
if(deltaTime > 1000) { | |
// debugger; | |
} | |
console.log('watch $digest', deltaTime, 'ms ttl', TTL - ttl, 'digest trigger by', this.$id); | |
next.$$digestStart = null; | |
} | |
current = current.$parent; | |
} | |
} | |
if(next && next.$id === window.trackScopeId) { | |
if(!next.$$digestStart) { | |
next.$$digestStart = performance.now(); | |
} else { | |
var deltaTime = (performance.now() - next.$$digestStart); | |
if(deltaTime > 1000) { | |
// debugger; | |
} | |
console.log('watch $digest', deltaTime, 'ms ttl', TTL - ttl, 'digest trigger by', this.$id); | |
next.$$digestStart = null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment