perf(ivy): add noop change detection scenario to the styling benchmark (#34775)

PR Close #34775
This commit is contained in:
Pawel Kozlowski 2020-01-14 15:15:09 +01:00 committed by atscott
parent 55047eaa10
commit 4f6924c622
3 changed files with 41 additions and 4 deletions

View File

@ -24,8 +24,10 @@
<button id="create">create</button> <button id="create">create</button>
<button id="update">update</button> <button id="update">update</button>
<button id="detect_changes">detect changes</button>
<button id="destroy">destroy</button> <button id="destroy">destroy</button>
<button id="profile_update">profile update</button> <button id="profile_update">profile update</button>
<button id="profile_detect_changes">profile detect changes</button>
<button id="modify">modify externally</button> <button id="modify">modify externally</button>
</p> </p>

View File

@ -41,6 +41,8 @@ export function init(moduleRef: NgModuleRef<StylingModule>) {
appRef.tick(); appRef.tick();
} }
function detectChanges() { appRef.tick(); }
function modifyExternally() { function modifyExternally() {
const buttonEls = componentHostEl.querySelectorAll('button') as HTMLButtonElement[]; const buttonEls = componentHostEl.querySelectorAll('button') as HTMLButtonElement[];
buttonEls.forEach((buttonEl: HTMLButtonElement) => { buttonEls.forEach((buttonEl: HTMLButtonElement) => {
@ -55,11 +57,17 @@ export function init(moduleRef: NgModuleRef<StylingModule>) {
bindAction('#create', () => create(select.selectedIndex)); bindAction('#create', () => create(select.selectedIndex));
bindAction('#update', update); bindAction('#update', update);
bindAction('#detect_changes', detectChanges);
bindAction('#destroy', destroy); bindAction('#destroy', destroy);
bindAction('#profile_update', profile(() => { bindAction('#profile_update', profile(() => {
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
update(); update();
} }
}, () => {}, 'update and detect changes')); }, () => {}, 'update and detect changes'));
bindAction('#profile_detect_changes', profile(() => {
for (let i = 0; i < 10; i++) {
detectChanges();
}
}, () => {}, 'noop detect changes'));
bindAction('#modify', modifyExternally); bindAction('#modify', modifyExternally);
} }

View File

@ -32,16 +32,34 @@ describe('styling benchmark spec', () => {
expect(items.first().getAttribute('title')).toBe('baz'); 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. // Create benchmarks for each possible test scenario.
SCENARIOS.forEach(({optionIndex, id}) => { SCENARIOS.forEach(({optionIndex, id}) => {
describe(id, () => { describe(id, () => {
it('should run detect_changes benchmark', done => { it('should run update benchmark', done => {
runStylingBenchmark(`styling.${id}.update`, { runStylingBenchmark(`styling.${id}.update`, {
work: () => update(), work: () => update(),
prepare: () => { prepare: () => {
// Switch to the current scenario by clicking the corresponding option. selectScenario(optionIndex);
element.all(by.tagName('option')).get(optionIndex).click(); create();
// Create the elements with styling. },
}).then(done, done.fail);
});
it('should run detect changes benchmark', done => {
runStylingBenchmark(`styling.${id}.noop_cd`, {
work: () => detectChanges(),
prepare: () => {
selectScenario(optionIndex);
create(); create();
}, },
}).then(done, done.fail); }).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() { function create() {
$('#create').click(); $('#create').click();
} }
@ -58,6 +81,10 @@ function update() {
$('#update').click(); $('#update').click();
} }
function detectChanges() {
$('#detect_changes').click();
}
/** /**
* Runs the styling benchmark with the given id and worker. The worker describes * Runs the styling benchmark with the given id and worker. The worker describes
* the actions that should run for preparation and measurement. * the actions that should run for preparation and measurement.