From 024765b86acc71f79c2a524dad6a535f7884f91d Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Thu, 5 Sep 2019 13:42:51 +0200 Subject: [PATCH] perf(ivy): introduce benchmark for listeners registration (#32495) PR Close #32495 --- packages/core/test/render3/perf/BUILD.bazel | 8 ++ .../core/test/render3/perf/listeners/index.ts | 101 ++++++++++++++++++ .../core/test/render3/perf/noop_renderer.ts | 2 +- 3 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 packages/core/test/render3/perf/listeners/index.ts diff --git a/packages/core/test/render3/perf/BUILD.bazel b/packages/core/test/render3/perf/BUILD.bazel index 9a3ec8a354..06e603af44 100644 --- a/packages/core/test/render3/perf/BUILD.bazel +++ b/packages/core/test/render3/perf/BUILD.bazel @@ -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", diff --git a/packages/core/test/render3/perf/listeners/index.ts b/packages/core/test/render3/perf/listeners/index.ts new file mode 100644 index 0000000000..6c81b84206 --- /dev/null +++ b/packages/core/test/render3/perf/listeners/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'; + +` +
+ + + + + + + + + + +
+`; +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(); \ No newline at end of file diff --git a/packages/core/test/render3/perf/noop_renderer.ts b/packages/core/test/render3/perf/noop_renderer.ts index 90fe67e9b1..e9c6c589bb 100644 --- a/packages/core/test/render3/perf/noop_renderer.ts +++ b/packages/core/test/render3/perf/noop_renderer.ts @@ -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 () => {}; } }