From 4f6924c622c88c566574251258e3fb13ee15fda4 Mon Sep 17 00:00:00 2001
From: Pawel Kozlowski
Date: Tue, 14 Jan 2020 15:15:09 +0100
Subject: [PATCH] perf(ivy): add noop change detection scenario to the styling
benchmark (#34775)
PR Close #34775
---
modules/benchmarks/src/styling/ng2/index.html | 2 ++
modules/benchmarks/src/styling/ng2/init.ts | 8 +++++
.../src/styling/styling_perf.spec.ts | 35 ++++++++++++++++---
3 files changed, 41 insertions(+), 4 deletions(-)
diff --git a/modules/benchmarks/src/styling/ng2/index.html b/modules/benchmarks/src/styling/ng2/index.html
index ad8723321f..90ef1d2fd2 100644
--- a/modules/benchmarks/src/styling/ng2/index.html
+++ b/modules/benchmarks/src/styling/ng2/index.html
@@ -24,8 +24,10 @@
+
+
diff --git a/modules/benchmarks/src/styling/ng2/init.ts b/modules/benchmarks/src/styling/ng2/init.ts
index 62a046fb13..e7816d80f8 100644
--- a/modules/benchmarks/src/styling/ng2/init.ts
+++ b/modules/benchmarks/src/styling/ng2/init.ts
@@ -41,6 +41,8 @@ export function init(moduleRef: NgModuleRef) {
appRef.tick();
}
+ function detectChanges() { appRef.tick(); }
+
function modifyExternally() {
const buttonEls = componentHostEl.querySelectorAll('button') as HTMLButtonElement[];
buttonEls.forEach((buttonEl: HTMLButtonElement) => {
@@ -55,11 +57,17 @@ export function init(moduleRef: NgModuleRef) {
bindAction('#create', () => create(select.selectedIndex));
bindAction('#update', update);
+ bindAction('#detect_changes', detectChanges);
bindAction('#destroy', destroy);
bindAction('#profile_update', profile(() => {
for (let i = 0; i < 10; i++) {
update();
}
}, () => {}, 'update and detect changes'));
+ bindAction('#profile_detect_changes', profile(() => {
+ for (let i = 0; i < 10; i++) {
+ detectChanges();
+ }
+ }, () => {}, 'noop detect changes'));
bindAction('#modify', modifyExternally);
}
diff --git a/modules/benchmarks/src/styling/styling_perf.spec.ts b/modules/benchmarks/src/styling/styling_perf.spec.ts
index 34bab527fc..c0383242fc 100644
--- a/modules/benchmarks/src/styling/styling_perf.spec.ts
+++ b/modules/benchmarks/src/styling/styling_perf.spec.ts
@@ -32,16 +32,34 @@ describe('styling benchmark spec', () => {
expect(items.first().getAttribute('title')).toBe('baz');
});
+ it('should render and run noop change detection', () => {
+ openBrowser({url: '/', ignoreBrowserSynchronization: true});
+ create();
+ const items = element.all(by.css('styling-bindings button'));
+ expect(items.count()).toBe(2000);
+ expect(items.first().getAttribute('title')).toBe('bar');
+ detectChanges();
+ expect(items.first().getAttribute('title')).toBe('bar');
+ });
+
// Create benchmarks for each possible test scenario.
SCENARIOS.forEach(({optionIndex, id}) => {
describe(id, () => {
- it('should run detect_changes benchmark', done => {
+ it('should run update benchmark', done => {
runStylingBenchmark(`styling.${id}.update`, {
work: () => update(),
prepare: () => {
- // Switch to the current scenario by clicking the corresponding option.
- element.all(by.tagName('option')).get(optionIndex).click();
- // Create the elements with styling.
+ selectScenario(optionIndex);
+ create();
+ },
+ }).then(done, done.fail);
+ });
+
+ it('should run detect changes benchmark', done => {
+ runStylingBenchmark(`styling.${id}.noop_cd`, {
+ work: () => detectChanges(),
+ prepare: () => {
+ selectScenario(optionIndex);
create();
},
}).then(done, done.fail);
@@ -50,6 +68,11 @@ describe('styling benchmark spec', () => {
});
});
+function selectScenario(optionIndex: number) {
+ // Switch to the current scenario by clicking the corresponding option.
+ element.all(by.tagName('option')).get(optionIndex).click();
+}
+
function create() {
$('#create').click();
}
@@ -58,6 +81,10 @@ function update() {
$('#update').click();
}
+function detectChanges() {
+ $('#detect_changes').click();
+}
+
/**
* Runs the styling benchmark with the given id and worker. The worker describes
* the actions that should run for preparation and measurement.