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

Commit

Permalink
perf(scope): 10x. Share the child scope class.
Browse files Browse the repository at this point in the history
This change causes Scope.$destory to run 10x faster. I suspect
Scope.$new is significantly faster as well, but I didn't measure it.
  • Loading branch information
jbdeboer authored and btford committed Apr 23, 2014
1 parent 828ad89 commit 8377e81
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/ng/rootScope.js
Expand Up @@ -181,18 +181,23 @@ function $RootScopeProvider(){
child.$$asyncQueue = this.$$asyncQueue;
child.$$postDigestQueue = this.$$postDigestQueue;
} else {
ChildScope = function() {}; // should be anonymous; This is so that when the minifier munges
// the name it does not become random set of chars. This will then show up as class
// name in the web inspector.
ChildScope.prototype = this;
child = new ChildScope();
child.$id = nextUid();
// Only create a child scope class if somebody asks for one,
// but cache it to allow the VM to optimize lookups.
if (!this.$$childScopeClass) {
this.$$childScopeClass = function() {
this.$$watchers = this.$$nextSibling =
this.$$childHead = this.$$childTail = null;
this.$$listeners = {};
this.$$listenerCount = {};
this.$id = nextUid();
this.$$childScopeClass = null;
};
this.$$childScopeClass.prototype = this;
}
child = new this.$$childScopeClass();
}
child['this'] = child;
child.$$listeners = {};
child.$$listenerCount = {};
child.$parent = this;
child.$$watchers = child.$$nextSibling = child.$$childHead = child.$$childTail = null;
child.$$prevSibling = this.$$childTail;
if (this.$$childHead) {
this.$$childTail.$$nextSibling = child;
Expand Down

0 comments on commit 8377e81

Please sign in to comment.