1
+ /* eslint-disable no-console */
2
+ /* eslint-disable no-undef */
1
3
import Route from '@ember/routing/route' ;
2
4
import { inject as service } from '@ember/service' ;
3
5
4
- const REMOVAL_COUNT = 10 ;
6
+ const DEBUG = false ;
5
7
6
8
export default Route . extend ( {
7
9
store : service ( ) ,
8
10
9
11
async model ( ) {
12
+ DEBUG && console . groupCollapsed ( 'test-setup' ) ;
10
13
performance . mark ( 'start-data-generation' ) ;
11
14
12
15
const initialPayload = await fetch ( './fixtures/big-many-to-many.json' ) . then ( ( r ) => r . json ( ) ) ;
13
16
const initialPayload2 = structuredClone ( initialPayload ) ;
14
17
const payloadWithRemoval = await fetch ( './fixtures/big-many-to-many-with-removal.json' ) . then ( ( r ) => r . json ( ) ) ;
18
+ // our relationship has 10 * number of colors generated members,
19
+ // so this keeps us in-sync with the fixture generation
20
+ const REMOVAL_COUNT =
21
+ initialPayload . data [ 0 ] . relationships . colors . data . length -
22
+ payloadWithRemoval . data [ 0 ] . relationships . colors . data . length ;
15
23
16
24
performance . mark ( 'start-push-initial-payload' ) ;
17
25
this . store . push ( initialPayload ) ;
@@ -27,24 +35,68 @@ export default Route.extend({
27
35
performance . mark ( 'start-relationship-materialization' ) ;
28
36
const seen = new Set ( ) ;
29
37
peekedCars . forEach ( ( car ) => iterateCar ( car , seen ) ) ;
38
+ seen . clear ( ) ;
30
39
const removedColors = [ ] ;
31
40
41
+ DEBUG && console . groupEnd ( ) ;
42
+ DEBUG && console . log ( structuredClone ( getWarpDriveMetricCounts ( ) ) ) ;
43
+
32
44
performance . mark ( 'start-local-removal' ) ;
45
+ console . groupCollapsed ( 'start-local-removal' ) ;
33
46
for ( const car of peekedCars ) {
34
47
const colors = car . colors ;
35
48
removedColors . push ( colors . splice ( 0 , REMOVAL_COUNT ) ) ;
36
49
}
50
+ peekedCars . forEach ( ( car ) => iterateCar ( car , seen ) ) ;
51
+ seen . clear ( ) ;
52
+
53
+ DEBUG && console . groupEnd ( ) ;
54
+ DEBUG && console . log ( structuredClone ( getWarpDriveMetricCounts ( ) ) ) ;
37
55
38
56
performance . mark ( 'start-push-minus-one-payload' ) ;
57
+ DEBUG && console . groupCollapsed ( 'start-push-minus-one-payload' ) ;
58
+
39
59
this . store . push ( payloadWithRemoval ) ;
60
+ DEBUG && console . groupEnd ( ) ;
61
+ DEBUG && console . log ( structuredClone ( getWarpDriveMetricCounts ( ) ) ) ;
40
62
41
63
performance . mark ( 'start-local-addition' ) ;
42
- peekedCars . forEach ( ( car , index ) => {
43
- car . colors = removedColors [ index ] . concat ( car . colors ) ;
44
- } ) ;
64
+ DEBUG && console . groupCollapsed ( 'start-local-addition' ) ;
65
+ // note, due to their position, the cars relationship on 50% of
66
+ // colors will end up reversed, causing us to generate a notification.
67
+ // this is because when we initially remove the colors from cars,
68
+ // we remove the car from wherever it occurs. When we re-add, that
69
+ // counts as re-adding "to the end" of the relationship since the
70
+ // removal was previously committed.
71
+ // To not generate a notification in this benchmark, the API response
72
+ // would need to account for the natural re-ordering of cars in the colors
73
+ // relationship.
74
+ //
75
+ // colors.cars = [1, 2, 3]
76
+ // cars.colors = [1, 2, 3]
77
+ // remove color 1 from cars.colors
78
+ // colors.cars = [2, 3]
79
+ // cars.colors = [2, 3]
80
+ // now add color-1 back to cars.colors at the front
81
+ // cars.colors = [1, 2, 3]
82
+ // colors.cars = [2, 3, 1] // notice order change
83
+ // but our payload will be [1, 2, 3] so we will generate a notification
84
+ // for colors.cars (we should not generate one for cars.colors)
85
+ for ( let i = 0 ; i < peekedCars . length ; i ++ ) {
86
+ const car = peekedCars [ i ] ;
87
+ car . colors = removedColors [ i ] . concat ( car . colors ) ;
88
+ }
89
+ peekedCars . forEach ( ( car ) => iterateCar ( car , seen ) ) ;
90
+ seen . clear ( ) ;
91
+
92
+ DEBUG && console . groupEnd ( ) ;
93
+ DEBUG && console . log ( structuredClone ( getWarpDriveMetricCounts ( ) ) ) ;
45
94
46
95
performance . mark ( 'start-push-plus-one-payload' ) ;
96
+ DEBUG && console . groupCollapsed ( 'start-push-plus-one-payload' ) ;
47
97
this . store . push ( initialPayload2 ) ;
98
+ DEBUG && console . groupEnd ( ) ;
99
+ DEBUG && console . log ( structuredClone ( getWarpDriveMetricCounts ( ) ) ) ;
48
100
49
101
performance . mark ( 'end-push-plus-one-payload' ) ;
50
102
} ,
0 commit comments