Skip to content

Instantly share code, notes, and snippets.

@stalluri
Created September 25, 2015 20:59
Show Gist options
  • Save stalluri/a33b89d2f1450f5bb47b to your computer and use it in GitHub Desktop.
Save stalluri/a33b89d2f1450f5bb47b to your computer and use it in GitHub Desktop.
Find number of angular watchers on a page; Less than 2000 is okay, beyond you might have performance issues
(function () {
var root = $(document.getElementsByTagName('body'));
var watchers = [];
var f = function (element) {
if (element.data().hasOwnProperty('$scope')) {
angular.forEach(element.data().$scope.$$watchers, function (watcher) {
watchers.push(watcher);
});
}
angular.forEach(element.children(), function (childElement) {
f($(childElement));
});
};
f(root);
console.log(watchers.length);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment