Skip to content

Commit

Permalink
Add extra performance tests (#7197)
Browse files Browse the repository at this point in the history
  • Loading branch information
pieter-v committed Jun 17, 2020
1 parent fd9ffb8 commit 3c633db
Show file tree
Hide file tree
Showing 10 changed files with 288 additions and 1 deletion.
63 changes: 63 additions & 0 deletions bin/relationship-performance-tracking/src/tracerbench.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,69 @@ const routes = [
},
],
},
{
routeName: 'add-children',
markers: [
{
start: 'start-push-initial-payload',
label: 'start-push-initial-payload',
},
{
start: 'end-push-initial-payload',
label: 'end-push-initial-payload',
},
{
start: 'start-push-update-payload',
label: 'start-push-update-payload',
},
{
start: 'end-push-update-payload',
label: 'end-push-update-payload',
},
],
},
{
routeName: 'unload',
markers: [
{
start: 'start-push-payload',
label: 'start-push-payload',
},
{
start: 'end-push-payload',
label: 'end-push-payload',
},
{
start: 'start-unloadRecord',
label: 'start-unloadRecord',
},
{
start: 'end-unloadRecord',
label: 'end-unloadRecord',
},
],
},
{
routeName: 'destroy',
markers: [
{
start: 'start-push-payload',
label: 'start-push-payload',
},
{
start: 'end-push-payload',
label: 'end-push-payload',
},
{
start: 'start-destroyRecord',
label: 'start-destroyRecord',
},
{
start: 'end-destroyRecord',
label: 'end-destroyRecord',
},
],
},
];

const browser = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import EmberObject from '@ember/object';

import { resolve } from 'rsvp';
import { Promise as EmberPromise, resolve } from 'rsvp';

export default class ApplicationMockAdapter extends EmberObject {
findAll() {
Expand All @@ -12,6 +12,9 @@ export default class ApplicationMockAdapter extends EmberObject {
shouldBackgroundReloadAll() {
return false;
}
deleteRecord = function() {
return EmberPromise.resolve();
};
}

const COLORS = ['red', 'white', 'black', 'pink', 'green', 'blue', 'yellow', 'orange', 'green', 'teal'];
Expand Down Expand Up @@ -74,6 +77,8 @@ function createCarsPayload(n) {
included: [].concat(colors, types, sizes),
};
performance.mark('end-fixture-generation');
performance.measure('fixture-generation', 'start-fixture-generation', 'end-fixture-generation');

return fixture;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import DS from 'ember-data';

const { Model, attr, belongsTo, hasMany } = DS;

export default Model.extend({
childName: attr('string'),
friends: hasMany('child', { async: true }),
bestFriend: belongsTo('child', { async: true }),
secondBestFriend: belongsTo('child', { async: true }),
parent: belongsTo('parent', { async: true }),
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import DS from 'ember-data';

const { Model, attr, hasMany } = DS;

export default Model.extend({
parentName: attr('string'),
children: hasMany('child', { async: true }),
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const Router = EmberRouter.extend({

Router.map(function() {
this.route('materialization');
this.route('add-children');
this.route('unload');
this.route('destroy');
});

export default Router;
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Route from '@ember/routing/route';

import { createParentPayload } from '../utils/create-parent-payload';
import { endTrace } from '../utils/end-trace';

export default Route.extend({
model() {
performance.mark('start-data-generation');

const initialPayload = createParentPayload(19600);
const updatePayload = createParentPayload(20000);

performance.mark('end-data-generation');
performance.measure('data-generation', 'start-data-generation', 'end-data-generation');

performance.mark('start-push-initial-payload');
this.store.push(initialPayload);
performance.mark('end-push-initial-payload');
performance.measure('push-initial-payload', 'start-push-initial-payload', 'end-push-initial-payload');

performance.mark('start-push-update-payload');
this.store.push(updatePayload);
performance.mark('end-push-update-payload');
performance.measure('push-update-payload', 'start-push-update-payload', 'end-push-update-payload');
},

afterModel() {
endTrace();
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import Route from '@ember/routing/route';
import { schedule } from '@ember/runloop';

import { all, Promise } from 'rsvp';

import { createParentPayload } from '../utils/create-parent-payload';
import { endTrace } from '../utils/end-trace';

export default Route.extend({
model() {
performance.mark('start-data-generation');

const payload = createParentPayload(2000, 500);

performance.mark('end-data-generation');
performance.measure('data-generation', 'start-data-generation', 'end-data-generation');

performance.mark('start-push-payload');
const result = this.store.push(payload);
performance.mark('end-push-payload');
performance.measure('push-payload', 'start-push-payload', 'end-push-payload');

performance.mark('start-destroyRecord');
const parent = result[0];
const childrenPromise = all(
parent
.get('children')
.toArray()
.map(child => child.destroyRecord().then(() => child.unloadRecord()))
);
const parentPromise = parent.destroyRecord().then(() => parent.unloadRecord());

return all([childrenPromise, parentPromise]).then(
() =>
new Promise((resolve, reject) => {
schedule('destroy', this, () => {
performance.mark('end-destroyRecord');
performance.measure('destroyRecord', 'start-destroyRecord', 'end-destroyRecord');
resolve();
});
})
);
},

afterModel() {
endTrace();
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ export default Route.extend({
});
performance.mark('stop-outer-materialization');
performance.measure('outer-materialization', 'start-outer-materialization', 'stop-outer-materialization');

performance.mark('end-find-all');
performance.measure('find-all', 'start-find-all', 'end-find-all');

return flattened;
});
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import Route from '@ember/routing/route';
import { schedule } from '@ember/runloop';

import { Promise } from 'rsvp';

import { createParentPayload } from '../utils/create-parent-payload';
import { endTrace } from '../utils/end-trace';

export default Route.extend({
model() {
performance.mark('start-data-generation');

const payload = createParentPayload(2000, 500);

performance.mark('end-data-generation');
performance.measure('data-generation', 'start-data-generation', 'end-data-generation');

performance.mark('start-push-payload');
const result = this.store.push(payload);
performance.mark('end-push-payload');
performance.measure('push-payload', 'start-push-payload', 'end-push-payload');

performance.mark('start-unloadRecord');
const parent = result[0];
parent
.get('children')
.toArray()
.forEach(child => child.unloadRecord());
parent.unloadRecord();

return new Promise((resolve, reject) => {
schedule('destroy', this, () => {
performance.mark('end-unloadRecord');
performance.measure('unloadRecord', 'start-unloadRecord', 'end-unloadRecord');
resolve();
});
});
},

afterModel() {
endTrace();
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* Creates a `parent` with `nrChildren` children and each `child` has `nrFriends` friends.
* If `nrFriends > 0` then each child also has a `bestFriend` and a `secondBestFriend`.
*/
export function createParentPayload(nrChildren, nrFriends) {
const parentId = '1';
const payload = {
data: [
{
id: parentId,
type: 'parent',
attributes: {
parentName: 'parent name',
},
relationships: {
children: {
data: [],
},
},
},
],
included: [],
};
const childrenRel = payload.data[0].relationships.children.data;
const included = payload.included;

for (let i = 0; i < nrChildren; i++) {
const childId = `${parentId}-${i}`;
let child = {
id: childId,
type: 'child',
};
childrenRel.push(child);

child = Object.assign({}, child, {
attributes: {
childName: `child-${childId}`,
},
});
included.push(child);

if (nrFriends > 0) {
Object.assign(child, {
relationships: {
friends: {
data: [],
},
bestFriend: {
data: {
id: `${parentId}-${(i + 1) % nrChildren}`,
type: 'child',
},
},
secondBestFriend: {
data: {
id: `${parentId}-${(i + 2) % nrChildren}`,
type: 'child',
},
},
},
});

const friendsRel = child.relationships.friends.data;
for (let j = 0; j < nrFriends; j++) {
friendsRel.push({
id: `${parentId}-${(i + 1) % nrChildren}`,
type: 'child',
});
}
}
}

return payload;
}

0 comments on commit 3c633db

Please sign in to comment.