Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(ivy): add ngIf-like directive to the ng_template benchmark #33595

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
69 changes: 44 additions & 25 deletions packages/core/test/render3/perf/ng_template/index.ts
Expand Up @@ -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';

`<div>
<ng-template></ng-template>
<ng-template></ng-template>
<ng-template></ng-template>
<ng-template></ng-template>
<ng-template></ng-template>
<ng-template></ng-template>
<ng-template></ng-template>
<ng-template></ng-template>
<ng-template></ng-template>
<ng-template></ng-template>
</div>
</ng-template>`;
class TemplateRefToken {
/**
* @internal
* @nocollapse
*/
static __NG_ELEMENT_ID__(): TemplateRef<any>|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) {}
}

`
<ng-template viewManipulation></ng-template>
<ng-template viewManipulation></ng-template>
`;
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);
Expand Down