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(core): use multiple directives in host bindings micro benchmark #35736

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
46 changes: 28 additions & 18 deletions packages/core/test/render3/perf/host_binding/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import {TAttributes} from '../../../../src/render3/interfaces/node';
import {createBenchmark} from '../micro_bench';
import {setupTestHarness} from '../setup';

`
// Number of Directives with Host Binding and Host Listener
// that should be generated for one element in a template.
const HOST_BINDING_DIRS_COUNT = 100;

function generateHostBindingDirDef() {
`
@Directive({
selector: '[hostBindingDir]'
})
Expand All @@ -25,24 +30,26 @@ import {setupTestHarness} from '../setup';
onClick(event: any): void {}
}
`;
class HostBindingDir {
static ɵfac() { return new HostBindingDir(); }
static ɵdir = ɵɵdefineDirective({
type: HostBindingDir,
selectors: [['', 'hostBindingDir', '']],
hostVars: 2,
hostBindings: function(rf: RenderFlags, ctx: any) {
if (rf & 1) {
ɵɵlistener('click', function() { return ctx.onClick(); });
}
if (rf & 2) {
ɵɵhostProperty('data-a', ctx.exp);
class HostBindingDir {
static ɵfac() { return new HostBindingDir(); }
static ɵdir = ɵɵdefineDirective({
type: HostBindingDir,
selectors: [['', 'hostBindingDir', '']],
hostVars: 2,
hostBindings: function(rf: RenderFlags, ctx: any) {
if (rf & 1) {
ɵɵlistener('click', function() { return ctx.onClick(); });
}
if (rf & 2) {
ɵɵhostProperty('data-a', ctx.exp);
}
}
}
});
});

exp = 'string-exp';
onClick() {}
exp = 'string-exp';
onClick() {}
}
return HostBindingDir.ɵdir;
}

`
Expand All @@ -56,7 +63,10 @@ function componentTemplateFn(rf: RenderFlags, ctx: any) {

const context: any = {};
const consts: TAttributes[] = [['hostBindingDir', '']];
const directives: DirectiveDefList = [HostBindingDir.ɵdir];
const directives: DirectiveDefList = [];
for (let i = 0; i < HOST_BINDING_DIRS_COUNT; i++) {
directives.push(generateHostBindingDirDef());
}
const harness = setupTestHarness(componentTemplateFn, 1, 0, 1000, context, consts, directives);

// Benchmark host bindings execution in *creation* mode
Expand Down