fix(render): only look for content tags in views that might have them.

Largetable benchmark with `interpolationAttr` and 200 rows / 20 columns:
Time for destroy/create pair dropped from about 1260ms to about 150ms.

Related to #2298, but does not really fix it as we are still slow
if people are using `<content>`.

Closes #2297
This commit is contained in:
Tobias Bosch
2015-06-02 14:14:10 -07:00
parent c2fa4b7191
commit ba7956f521
5 changed files with 49 additions and 6 deletions
@@ -16,17 +16,28 @@ import {DOM} from 'angular2/src/dom/dom_adapter';
import {Content} from 'angular2/src/render/dom/shadow_dom/content_tag';
import {LightDom} from 'angular2/src/render/dom/shadow_dom/light_dom';
import {DomView} from 'angular2/src/render/dom/view/view';
import {DomProtoView} from 'angular2/src/render/dom/view/proto_view';
import {DomViewContainer} from 'angular2/src/render/dom/view/view_container';
@proxy
@IMPLEMENTS(DomProtoView)
class FakeProtoView extends SpyObject {
constructor(public transitiveContentTagCount: number) { super(DomProtoView); }
noSuchMethod(i) { super.noSuchMethod(i); }
}
@proxy
@IMPLEMENTS(DomView)
class FakeView extends SpyObject {
boundElements;
contentTags;
viewContainers;
proto;
constructor(containers = null) {
constructor(containers = null, transitiveContentTagCount: number = 1) {
super(DomView);
this.proto = new FakeProtoView(transitiveContentTagCount);
this.boundElements = [];
this.contentTags = [];
this.viewContainers = [];
@@ -109,7 +120,7 @@ export function main() {
beforeEach(() => { lightDomView = new FakeView(); });
describe("contentTags", () => {
it("should collect content tags from element injectors", () => {
it("should collect unconditional content tags", () => {
var tag = new FakeContentTag(el('<script></script>'));
var shadowDomView = new FakeView([tag]);
@@ -126,6 +137,15 @@ export function main() {
expect(lightDom.contentTags()).toEqual([tag]);
});
it("should not walk views that can't have content tags", () => {
var tag = new FakeContentTag(el('<script></script>'));
var shadowDomView = new FakeView([tag], 0);
var lightDom = createLightDom(lightDomView, shadowDomView, el("<div></div>"));
expect(lightDom.contentTags()).toEqual([]);
});
});
describe("expandedDomNodes", () => {
@@ -31,7 +31,8 @@ export function main() {
binders = [];
}
var rootEl = el('<div></div>');
return new DomProtoView({element: rootEl, elementBinders: binders});
return new DomProtoView(
{element: rootEl, elementBinders: binders, transitiveContentTagCount: 0});
}
function createView(pv = null, boundElementCount = 0) {