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

Commit 8377e81

Browse files
jbdeboerbtford
authored andcommitted
perf(scope): 10x. Share the child scope class.
This change causes Scope.$destory to run 10x faster. I suspect Scope.$new is significantly faster as well, but I didn't measure it.
1 parent 828ad89 commit 8377e81

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/ng/rootScope.js

+14-9
Original file line numberDiff line numberDiff line change
@@ -181,18 +181,23 @@ function $RootScopeProvider(){
181181
child.$$asyncQueue = this.$$asyncQueue;
182182
child.$$postDigestQueue = this.$$postDigestQueue;
183183
} else {
184-
ChildScope = function() {}; // should be anonymous; This is so that when the minifier munges
185-
// the name it does not become random set of chars. This will then show up as class
186-
// name in the web inspector.
187-
ChildScope.prototype = this;
188-
child = new ChildScope();
189-
child.$id = nextUid();
184+
// Only create a child scope class if somebody asks for one,
185+
// but cache it to allow the VM to optimize lookups.
186+
if (!this.$$childScopeClass) {
187+
this.$$childScopeClass = function() {
188+
this.$$watchers = this.$$nextSibling =
189+
this.$$childHead = this.$$childTail = null;
190+
this.$$listeners = {};
191+
this.$$listenerCount = {};
192+
this.$id = nextUid();
193+
this.$$childScopeClass = null;
194+
};
195+
this.$$childScopeClass.prototype = this;
196+
}
197+
child = new this.$$childScopeClass();
190198
}
191199
child['this'] = child;
192-
child.$$listeners = {};
193-
child.$$listenerCount = {};
194200
child.$parent = this;
195-
child.$$watchers = child.$$nextSibling = child.$$childHead = child.$$childTail = null;
196201
child.$$prevSibling = this.$$childTail;
197202
if (this.$$childHead) {
198203
this.$$childTail.$$nextSibling = child;

0 commit comments

Comments
 (0)