Skip to content
Permalink
Browse files

perf(ivy): introduce benchmark for listeners registration (#32495)

PR Close #32495
  • Loading branch information...
pkozlowski-opensource authored and kara committed Sep 5, 2019
1 parent eab959a commit 024765b86acc71f79c2a524dad6a535f7884f91d
@@ -29,6 +29,14 @@ ng_rollup_bundle(
],
)

ng_rollup_bundle(
name = "listeners",
entry_point = ":listeners/index.ts",
deps = [
":perf_lib",
],
)

ng_rollup_bundle(
name = "noop_change_detection",
entry_point = ":noop_change_detection/index.ts",
@@ -0,0 +1,101 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* 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 {ɵɵelementEnd, ɵɵelementStart} from '../../../../src/render3/instructions/element';
import {ɵɵlistener} from '../../../../src/render3/instructions/listener';
import {createTNode, createTView} from '../../../../src/render3/instructions/shared';
import {RenderFlags} from '../../../../src/render3/interfaces/definition';
import {TNodeType, TViewNode} from '../../../../src/render3/interfaces/node';
import {resetComponentState} from '../../../../src/render3/state';
import {createBenchmark} from '../micro_bench';
import {createAndRenderLView} from '../setup';

`
<div>
<button (click)="clickListener()" (input)="inputListener()"></button>
<button (click)="clickListener()" (input)="inputListener()"></button>
<button (click)="clickListener()" (input)="inputListener()"></button>
<button (click)="clickListener()" (input)="inputListener()"></button>
<button (click)="clickListener()" (input)="inputListener()"></button>
<button (click)="clickListener()" (input)="inputListener()"></button>
<button (click)="clickListener()" (input)="inputListener()"></button>
<button (click)="clickListener()" (input)="inputListener()"></button>
<button (click)="clickListener()" (input)="inputListener()"></button>
<button (click)="clickListener()" (input)="inputListener()"></button>
</div>
`;
const _c0 = [3, 'click', 'input'];
function testTemplate(rf: RenderFlags, ctx: any) {
if (rf & 1) {
ɵɵelementStart(0, 'div');
ɵɵelementStart(1, 'button', _c0);
ɵɵlistener('click', function clickListener() {});
ɵɵlistener('input', function inputListener() {});
ɵɵelementEnd();
ɵɵelementStart(2, 'button', _c0);
ɵɵlistener('click', function clickListener() {});
ɵɵlistener('input', function inputListener() {});
ɵɵelementEnd();
ɵɵelementStart(3, 'button', _c0);
ɵɵlistener('click', function clickListener() {});
ɵɵlistener('input', function inputListener() {});
ɵɵelementEnd();
ɵɵelementStart(4, 'button', _c0);
ɵɵlistener('click', function clickListener() {});
ɵɵlistener('input', function inputListener() {});
ɵɵelementEnd();
ɵɵelementStart(5, 'button', _c0);
ɵɵlistener('click', function clickListener() {});
ɵɵlistener('input', function inputListener() {});
ɵɵelementEnd();
ɵɵelementStart(6, 'button', _c0);
ɵɵlistener('click', function clickListener() {});
ɵɵlistener('input', function inputListener() {});
ɵɵelementEnd();
ɵɵelementStart(7, 'button', _c0);
ɵɵlistener('click', function clickListener() {});
ɵɵlistener('input', function inputListener() {});
ɵɵelementEnd();
ɵɵelementStart(8, 'button', _c0);
ɵɵlistener('click', function clickListener() {});
ɵɵlistener('input', function inputListener() {});
ɵɵelementEnd();
ɵɵelementStart(9, 'button', _c0);
ɵɵlistener('click', function clickListener() {});
ɵɵlistener('input', function inputListener() {});
ɵɵelementEnd();
ɵɵelementStart(10, 'button', _c0);
ɵɵlistener('click', function clickListener() {});
ɵɵlistener('input', function inputListener() {});
ɵɵelementEnd();
ɵɵelementEnd();
}
}

const viewTNode = createTNode(null !, null, TNodeType.View, -1, null, null) as TViewNode;
const embeddedTView = createTView(-1, testTemplate, 11, 0, null, null, null, null);

// initialize global state
resetComponentState();

// create view once so we don't profile first template pass
createAndRenderLView(null, embeddedTView, viewTNode);

const listenersCreate = createBenchmark('listeners create', 500000, 20);
const createTime = listenersCreate('create');

// profile create views (run templates in creation mode)
console.profile('create listeners');
while (createTime.run()) {
while (createTime()) {
createAndRenderLView(null, embeddedTView, viewTNode);
}
}
console.profileEnd();

// report results
listenersCreate.report();
@@ -46,7 +46,7 @@ export class NoopRenderer implements ProceduralRenderer3 {
listen(
target: RNode|'document'|'window'|'body', eventName: string,
callback: (event: any) => boolean | void): () => void {
throw new Error('Method not implemented.');
return () => {};
}
}

0 comments on commit 024765b

Please sign in to comment.
You can’t perform that action at this time.