Skip to content

Commit 85d9524

Browse files
gitKrystanMehulKChaudhari
authored andcommitted
Add perf test for replacing state with new state that matches local state (emberjs#9703)
* Add perf test for replacing state with new state that matches local state * Fix typo * Simplify
1 parent a772ac9 commit 85d9524

File tree

5 files changed

+75
-0
lines changed

5 files changed

+75
-0
lines changed

.github/workflows/perf-check.yml

+5
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ jobs:
104104
"control": "http://localhost:4200/unused-relationships",
105105
"experiment": "http://localhost:4201/unused-relationships",
106106
"markers": "start-push-payload,end-push-payload"
107+
},
108+
"update-with-same-state": {
109+
"control": "http://localhost:4200/update-with-same-state",
110+
"experiment": "http://localhost:4201/update-with-same-state",
111+
"markers": "start-data-generation,start-push-initial-payload,start-peek-records,start-record-materialization,start-relationship-materialization,start-local-removal,start-push-minus-one-payload,start-local-addition,start-push-plus-one-payload,end-push-plus-one-payload"
107112
}
108113
}
109114
fidelity: 60

.github/workflows/perf-over-release.yml

+5
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ jobs:
103103
"control": "http://localhost:4200/unused-relationships",
104104
"experiment": "http://localhost:4201/unused-relationships",
105105
"markers": "start-push-payload,end-push-payload"
106+
},
107+
"update-with-same-state": {
108+
"control": "http://localhost:4200/update-with-same-state",
109+
"experiment": "http://localhost:4201/update-with-same-state",
110+
"markers": "start-data-generation,start-push-initial-payload,start-peek-records,start-record-materialization,start-relationship-materialization,start-local-removal,start-push-minus-one-payload,start-local-addition,start-push-plus-one-payload,end-push-plus-one-payload"
106111
}
107112
}
108113
fidelity: 60

tests/performance/app/router.js

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Router.map(function () {
1818
this.route('unload-all');
1919
this.route('destroy');
2020
this.route('unused-relationships');
21+
this.route('update-with-same-state');
2122
});
2223

2324
export default Router;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import Route from '@ember/routing/route';
2+
import { inject as service } from '@ember/service';
3+
4+
export default Route.extend({
5+
store: service(),
6+
7+
async model() {
8+
performance.mark('start-data-generation');
9+
10+
const initialPayload = await fetch('./fixtures/add-children-initial.json').then((r) => r.json());
11+
const initialPayload2 = structuredClone(initialPayload);
12+
13+
const minusOnePayload = structuredClone(initialPayload);
14+
minusOnePayload.data.relationships.children.data.pop();
15+
minusOnePayload.included.pop();
16+
17+
performance.mark('start-push-initial-payload');
18+
this.store.push(initialPayload);
19+
20+
performance.mark('start-peek-records');
21+
const peekedChildren = this.store.peekAll('child');
22+
const peekedParents = this.store.peekAll('parent');
23+
24+
performance.mark('start-record-materialization');
25+
peekedChildren.slice();
26+
peekedParents.slice();
27+
28+
performance.mark('start-relationship-materialization');
29+
const seen = new Set();
30+
peekedParents.forEach((parent) => iterateParent(parent, seen));
31+
const parent = peekedParents[0];
32+
const children = await parent.children;
33+
34+
performance.mark('start-local-removal');
35+
const removedChild = children.pop();
36+
37+
performance.mark('start-push-minus-one-payload');
38+
this.store.push(minusOnePayload);
39+
40+
performance.mark('start-local-addition');
41+
children.push(removedChild);
42+
43+
performance.mark('start-push-plus-one-payload');
44+
this.store.push(initialPayload2);
45+
46+
performance.mark('end-push-plus-one-payload');
47+
},
48+
});
49+
50+
function iterateChild(record, seen) {
51+
if (seen.has(record)) {
52+
return;
53+
}
54+
seen.add(record);
55+
56+
record.bestFriend.get('name');
57+
record.secondBestFriend.get('name');
58+
record.friends.forEach((child) => iterateChild(child, seen));
59+
}
60+
function iterateParent(record, seen) {
61+
seen.add(record);
62+
record.children.forEach((child) => iterateChild(child, seen));
63+
}

tests/performance/app/templates/application.hbs

+1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
<li><LinkTo @route='add-children-to-materialized'>Add Children To Materialized</LinkTo></li>
1111
<li><LinkTo @route='add-children-then-materialize'>Add Children Then Materialize</LinkTo></li>
1212
<li><LinkTo @route='unused-relationships'>Unused Relationships</LinkTo></li>
13+
<li><LinkTo @route='update-with-same-state'>Update With Same State</LinkTo></li>
1314
</ol>

0 commit comments

Comments
 (0)