From e89c2dd8d0ac47dbaefc8bb3e1b2b8d12a454566 Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Mon, 4 Nov 2019 15:16:54 +0100 Subject: [PATCH] perf(ivy): add ngIf-like directive to the ng_template benchmark (#33595) PR Close #33595 --- .../test/render3/perf/ng_template/index.ts | 69 ++++++++++++------- 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/packages/core/test/render3/perf/ng_template/index.ts b/packages/core/test/render3/perf/ng_template/index.ts index 39736721f0..63ab566e87 100644 --- a/packages/core/test/render3/perf/ng_template/index.ts +++ b/packages/core/test/render3/perf/ng_template/index.ts @@ -5,43 +5,62 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {ɵɵtemplate} from '../../../../src/render3/instructions/container'; +import {ElementRef, TemplateRef, ViewContainerRef} from '../../../../src/linker'; + +import {ɵɵdefineDirective, ɵɵdirectiveInject, ɵɵtemplate} from '../../../../src/render3/index'; import {createTNode, createTView} from '../../../../src/render3/instructions/shared'; import {RenderFlags} from '../../../../src/render3/interfaces/definition'; import {TNodeType, TViewNode} from '../../../../src/render3/interfaces/node'; +import {injectTemplateRef, injectViewContainerRef} from '../../../../src/render3/view_engine_compatibility'; import {createBenchmark} from '../micro_bench'; import {createAndRenderLView} from '../setup'; -`
- - - - - - - - - - -
-`; +class TemplateRefToken { + /** + * @internal + * @nocollapse + */ + static __NG_ELEMENT_ID__(): TemplateRef|null { + return injectTemplateRef(TemplateRef, ElementRef); + } +} +class ViewContainerRefToken { + /** + * @internal + * @nocollapse + */ + static __NG_ELEMENT_ID__(): ViewContainerRef { + return injectViewContainerRef(ViewContainerRef, ElementRef); + } +} + +class NgIfLike { + static ɵfac() { + return new NgIfLike( + ɵɵdirectiveInject(TemplateRefToken), ɵɵdirectiveInject(ViewContainerRefToken)); + } + static ɵdir = ɵɵdefineDirective({ + type: NgIfLike, + selectors: [['', 'viewManipulation', '']], + }); + + constructor(private tplRef: TemplateRefToken, private vcRef: ViewContainerRefToken) {} +} + +` + + +`; function testTemplate(rf: RenderFlags, ctx: any) { if (rf & 1) { - ɵɵtemplate(0, null, 0, 0); - ɵɵtemplate(1, null, 0, 0); - ɵɵtemplate(2, null, 0, 0); - ɵɵtemplate(3, null, 0, 0); - ɵɵtemplate(4, null, 0, 0); - ɵɵtemplate(5, null, 0, 0); - ɵɵtemplate(6, null, 0, 0); - ɵɵtemplate(7, null, 0, 0); - ɵɵtemplate(8, null, 0, 0); - ɵɵtemplate(9, null, 0, 0); + ɵɵtemplate(0, null, 0, 0, 'ng-template', 0); + ɵɵtemplate(1, null, 0, 0, 'ng-template', 0); } } const viewTNode = createTNode(null !, null, TNodeType.View, -1, null, null) as TViewNode; -const embeddedTView = createTView(-1, testTemplate, 10, 0, null, null, null, null, null); +const embeddedTView = createTView( + -1, testTemplate, 2, 0, [NgIfLike.ɵdir], null, null, null, [['viewManipulation', '']]); // create view once so we don't profile first template pass createAndRenderLView(null, embeddedTView, viewTNode);