Skip to content

Commit 7b22706

Browse files
committedMar 7, 2025
stash stuffs
1 parent cb09220 commit 7b22706

File tree

7 files changed

+60
-23
lines changed

7 files changed

+60
-23
lines changed
 

‎packages/graph/src/-private/-diff.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,17 @@ function _compare<T>(
164164
const prevLength = prevState.length;
165165
const iterationLength = Math.max(finalLength, prevLength);
166166
const equalLength = finalLength === prevLength;
167-
let changed: boolean = finalSet.size !== prevSet.size;
168-
let remoteOrderChanged = false;
167+
let remoteOrderChanged = finalSet.size !== prevSet.size;
168+
let changed: boolean = priorLocalState ? finalSet.size !== priorLocalState.length : remoteOrderChanged;
169169
const added = new Set<T>();
170170
const removed = new Set<T>();
171171
const priorLocalLength = priorLocalState?.length ?? 0;
172172

173+
changed &&
174+
console.log(
175+
`changed because ${priorLocalState ? 'finalSet.size !== priorLocalState.length' : 'finalSet.size !== prevSet.size'}`
176+
);
177+
173178
for (let i = 0; i < iterationLength; i++) {
174179
let member: T | undefined;
175180

@@ -181,6 +186,7 @@ function _compare<T>(
181186
if (i < priorLocalLength) {
182187
const priorLocalMember = priorLocalState![i];
183188
if (priorLocalMember !== member) {
189+
!changed && console.log(`changed because priorLocalMember !== member && !prevSet.has(member)`);
184190
changed = true;
185191
}
186192
}
@@ -214,9 +220,11 @@ function _compare<T>(
214220
if (i < priorLocalLength) {
215221
const priorLocalMember = priorLocalState![i];
216222
if (priorLocalMember !== member) {
223+
!changed && console.log(`changed because priorLocalMember !== member && member !== prevMember`);
217224
changed = true;
218225
}
219226
} else {
227+
!changed && console.log(`changed because priorLocalMember !== member && index >= priorLocalLength`);
220228
changed = true;
221229
}
222230
}
@@ -236,6 +244,7 @@ function _compare<T>(
236244
}
237245

238246
if (!finalSet.has(prevMember)) {
247+
!changed && console.log(`changed because !finalSet.has(prevMember)`);
239248
changed = true;
240249
removed.add(prevMember);
241250
onDel(prevMember);

‎packages/graph/src/-private/operations/replace-related-records.ts

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export default function replaceRelatedRecords(graph: Graph, op: ReplaceRelatedRe
7575
}
7676
}
7777

78+
// FIXME: Add metric count for number of calls to this
7879
function replaceRelatedRecordsLocal(graph: Graph, op: ReplaceRelatedRecordsOperation, isRemote: boolean) {
7980
const identifiers = op.value;
8081
const relationship = graph.get(op.record, op.field);
@@ -160,6 +161,7 @@ function replaceRelatedRecordsLocal(graph: Graph, op: ReplaceRelatedRecordsOpera
160161
}
161162
}
162163

164+
// FIXME: Add metric count for number of calls to this
163165
function replaceRelatedRecordsRemote(graph: Graph, op: ReplaceRelatedRecordsOperation, isRemote: boolean) {
164166
const identifiers = op.value;
165167
const relationship = graph.get(op.record, op.field);

‎tests/performance/app/routes/update-with-same-state-m2m.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1+
// FIXME: Don't merge disables
2+
/* eslint-disable no-console */
3+
/* eslint-disable no-undef */
14
import Route from '@ember/routing/route';
25
import { inject as service } from '@ember/service';
36

4-
const REMOVAL_COUNT = 10;
7+
const REMOVAL_COUNT = 1;
58

69
export default Route.extend({
710
store: service(),
811

912
async model() {
13+
console.groupCollapsed('test-setup');
1014
performance.mark('start-data-generation');
1115

1216
const initialPayload = await fetch('./fixtures/big-many-to-many.json').then((r) => r.json());
@@ -27,24 +31,46 @@ export default Route.extend({
2731
performance.mark('start-relationship-materialization');
2832
const seen = new Set();
2933
peekedCars.forEach((car) => iterateCar(car, seen));
34+
seen.clear();
3035
const removedColors = [];
3136

37+
console.groupEnd();
38+
console.log(structuredClone(getWarpDriveMetricCounts()));
39+
3240
performance.mark('start-local-removal');
41+
console.groupCollapsed('start-local-removal');
3342
for (const car of peekedCars) {
3443
const colors = car.colors;
3544
removedColors.push(colors.splice(0, REMOVAL_COUNT));
45+
iterateCar(car, seen);
3646
}
47+
seen.clear();
48+
49+
console.groupEnd();
50+
console.log(structuredClone(getWarpDriveMetricCounts()));
3751

3852
performance.mark('start-push-minus-one-payload');
53+
console.groupCollapsed('start-push-minus-one-payload');
3954
this.store.push(payloadWithRemoval);
55+
console.groupEnd();
56+
console.log(structuredClone(getWarpDriveMetricCounts()));
4057

4158
performance.mark('start-local-addition');
59+
console.groupCollapsed('start-local-addition');
4260
peekedCars.forEach((car, index) => {
4361
car.colors = removedColors[index].concat(car.colors);
62+
iterateCar(car, seen);
4463
});
64+
seen.clear();
65+
66+
console.groupEnd();
67+
console.log(structuredClone(getWarpDriveMetricCounts()));
4568

4669
performance.mark('start-push-plus-one-payload');
70+
console.groupCollapsed('start-push-plus-one-payload');
4771
this.store.push(initialPayload2);
72+
console.groupEnd();
73+
console.log(structuredClone(getWarpDriveMetricCounts()));
4874

4975
performance.mark('end-push-plus-one-payload');
5076
},

‎tests/performance/ember-cli-build.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ module.exports = async function (defaults) {
1111
setConfig(app, __dirname, {
1212
compatWith: '99',
1313
debug: {
14-
// LOG_NOTIFICATIONS: true,
14+
LOG_NOTIFICATIONS: true,
1515
// LOG_INSTANCE_CACHE: true,
16-
// LOG_METRIC_COUNTS: true,
16+
LOG_METRIC_COUNTS: true,
1717
},
1818
});
1919

Binary file not shown.
Binary file not shown.

‎tests/performance/fixtures/index.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,26 @@ const createParentRecords = require('./create-parent-records');
2828
const { createComplexPayload: createComplexRecordsPayload } = require('./create-complex-payload.ts');
2929

3030
async function main() {
31-
const initialChildrenPayload = createParentPayload(19600);
32-
write('add-children-initial', initialChildrenPayload);
33-
write('add-children-final', createParentPayload(20000));
34-
const payloadWithRemoval = structuredClone(initialChildrenPayload);
35-
payloadWithRemoval.data.relationships.children.data.splice(0, 19000);
36-
payloadWithRemoval.included.splice(0, 19000);
37-
write('add-children-with-removal', payloadWithRemoval);
31+
// const initialChildrenPayload = createParentPayload(19600);
32+
// write('add-children-initial', initialChildrenPayload);
33+
// write('add-children-final', createParentPayload(20000));
34+
// const payloadWithRemoval = structuredClone(initialChildrenPayload);
35+
// payloadWithRemoval.data.relationships.children.data.splice(0, 19000);
36+
// payloadWithRemoval.included.splice(0, 19000);
37+
// write('add-children-with-removal', payloadWithRemoval);
3838

39-
write('destroy', createParentPayload(500, 50));
40-
write('relationship-materialization-simple', createCarsPayload(10000));
41-
write('relationship-materialization-complex', createParentRecords(200, 10, 20));
42-
write('unload', createParentPayload(500, 50));
43-
write('unload-all', createParentRecords(1000, 5, 10));
44-
write('unused-relationships', createParentPayload(500, 50));
45-
write('example-car', createCarsPayload(1));
46-
write('example-parent', createParentPayload(2, 2));
47-
write('basic-record-materialization', createParentRecords(10000, 2, 3));
48-
write('complex-record-materialization', await createComplexRecordsPayload(400));
39+
// write('destroy', createParentPayload(500, 50));
40+
// write('relationship-materialization-simple', createCarsPayload(10000));
41+
// write('relationship-materialization-complex', createParentRecords(200, 10, 20));
42+
// write('unload', createParentPayload(500, 50));
43+
// write('unload-all', createParentRecords(1000, 5, 10));
44+
// write('unused-relationships', createParentPayload(500, 50));
45+
// write('example-car', createCarsPayload(1));
46+
// write('example-parent', createParentPayload(2, 2));
47+
// write('basic-record-materialization', createParentRecords(10000, 2, 3));
48+
// write('complex-record-materialization', await createComplexRecordsPayload(400));
4949

50-
const initialBigM2M = createCarsPayload(100, 100);
50+
const initialBigM2M = createCarsPayload(2, 2);
5151
write('big-many-to-many', initialBigM2M);
5252
write('big-many-to-many-with-removal', deleteHalfTheColors(initialBigM2M));
5353
}

0 commit comments

Comments
 (0)