Fixed a Profiler memoization bug and improved test coverage
Brian Vaughn committed
May 8, 2019 at 15:41 UTC
ee099124e241778d5d398b48c8eef99bc9c66361
4 files changed
+318
-193
src/__tests__/__snapshots__/profiling-test.js.snap
+256
-159
@@ -3,10 +3,11 @@
3
exports[`profiling CommitDetails should be collected for each commit: CommitDetails commitIndex: 0 1`] = `
4
Object {
5
"actualDurations": Map {
6
- 1 => 14,
7
- 2 => 14,
8
- 3 => 2,
9
- 4 => 2,
6
+ 1 => 12,
7
+ 2 => 12,
8
+ 3 => 0,
9
+ 4 => 1,
10
+ 5 => 1,
11
},
12
"commitIndex": 0,
13
"interactions": Array [],
@@ -17,11 +18,11 @@ Object {
18
exports[`profiling CommitDetails should be collected for each commit: CommitDetails commitIndex: 1 1`] = `
19
Object {
20
"actualDurations": Map {
20
- 3 => 2,
21
- 4 => 2,
22
- 5 => 2,
23
- 2 => 16,
24
- 1 => 16,
21
+ 3 => 0,
22
+ 4 => 1,
23
+ 6 => 2,
24
+ 2 => 13,
25
+ 1 => 13,
26
},
27
"commitIndex": 1,
28
"interactions": Array [],
@@ -32,9 +33,9 @@ Object {
33
exports[`profiling CommitDetails should be collected for each commit: CommitDetails commitIndex: 2 1`] = `
34
Object {
35
"actualDurations": Map {
35
- 3 => 2,
36
- 2 => 12,
37
- 1 => 12,
36
+ 3 => 0,
37
+ 2 => 10,
38
+ 1 => 10,
39
},
40
"commitIndex": 2,
41
"interactions": Array [],
@@ -60,13 +61,15 @@ Object {
61
Object {
62
"actualDurations": Array [
63
1,
63
- 14,
64
+ 12,
65
2,
65
- 14,
66
+ 12,
67
3,
67
- 2,
68
+ 0,
69
4,
69
- 2,
70
+ 1,
71
+ 5,
72
+ 1,
73
],
74
"commitIndex": 0,
75
"interactions": Array [],
@@ -75,15 +78,15 @@ Object {
78
Object {
79
"actualDurations": Array [
80
3,
78
- 2,
81
+ 0,
82
4,
80
- 2,
81
- 5,
83
+ 1,
84
+ 6,
85
2,
86
2,
84
- 16,
87
+ 13,
88
1,
86
- 16,
89
+ 13,
90
],
91
"commitIndex": 1,
92
"interactions": Array [],
@@ -92,11 +95,11 @@ Object {
95
Object {
96
"actualDurations": Array [
97
3,
98
+ 0,
99
2,
96
- 2,
97
- 12,
100
+ 10,
101
1,
99
- 12,
102
+ 10,
103
],
104
"commitIndex": 2,
105
"interactions": Array [],
@@ -123,7 +126,7 @@ Object {
126
Array [
127
1,
128
1,
126
- 17,
129
+ 29,
130
6,
131
80,
132
97,
@@ -141,6 +144,18 @@ Object {
144
48,
145
1,
146
49,
147
+ 11,
148
+ 77,
149
+ 101,
150
+ 109,
151
+ 111,
152
+ 40,
153
+ 67,
154
+ 104,
155
+ 105,
156
+ 108,
157
+ 100,
158
+ 41,
159
1,
160
1,
161
11,
@@ -148,7 +163,7 @@ Object {
163
1,
164
4,
165
1,
151
- 14000,
166
+ 12000,
167
1,
168
2,
169
5,
@@ -158,7 +173,7 @@ Object {
173
0,
174
4,
175
2,
161
- 14000,
176
+ 12000,
177
1,
178
3,
179
5,
@@ -168,7 +183,7 @@ Object {
183
3,
184
4,
185
3,
171
- 2000,
186
+ 0,
187
1,
188
4,
189
5,
@@ -178,7 +193,17 @@ Object {
193
4,
194
4,
195
4,
181
- 2000,
196
+ 1000,
197
+ 1,
198
+ 5,
199
+ 8,
200
+ 2,
201
+ 2,
202
+ 5,
203
+ 0,
204
+ 4,
205
+ 5,
206
+ 1000,
207
],
208
Array [
209
1,
@@ -193,27 +218,28 @@ Object {
218
1,
219
50,
220
1,
196
- 5,
221
+ 6,
222
5,
223
2,
224
2,
225
1,
226
2,
227
4,
203
- 5,
228
+ 6,
229
2000,
230
4,
231
2,
207
- 16000,
232
+ 14000,
233
3,
234
2,
210
- 3,
235
+ 4,
236
3,
237
4,
238
+ 6,
239
5,
240
4,
241
1,
216
- 16000,
242
+ 14000,
243
],
244
Array [
245
1,
@@ -221,14 +247,19 @@ Object {
247
0,
248
2,
249
2,
224
- 5,
250
+ 6,
251
4,
252
4,
253
2,
228
- 12000,
254
+ 11000,
255
+ 3,
256
+ 2,
257
+ 2,
258
+ 3,
259
+ 5,
260
4,
261
1,
231
- 12000,
262
+ 11000,
263
],
264
Array [
265
1,
@@ -237,12 +268,6 @@ Object {
268
2,
269
1,
270
3,
240
- 4,
241
- 2,
242
- 10000,
243
- 4,
244
- 1,
245
- 10000,
271
],
272
],
273
},
@@ -251,16 +276,16 @@ Object {
276
},
277
"profilingSummary": Object {
278
"commitDurations": Array [
254
- 14,
255
- 16,
279
12,
280
+ 13,
281
+ 10,
282
10,
283
],
284
"commitTimes": Array [
260
- 14,
261
- 30,
262
- 42,
263
- 52,
285
+ 12,
286
+ 25,
287
+ 35,
288
+ 45,
289
],
290
"initialTreeBaseDurations": Array [],
291
"interactionCount": 0,
@@ -274,11 +299,11 @@ exports[`profiling FiberCommits should be collected for each rendered fiber: Fib
299
Object {
300
"commitDurations": Array [
301
0,
277
- 12,
302
+ 11,
303
1,
279
- 14,
304
+ 11,
305
2,
281
- 16,
306
+ 13,
307
],
308
"fiberID": 2,
309
"rootID": 1,
@@ -289,11 +314,11 @@ exports[`profiling FiberCommits should be collected for each rendered fiber: Fib
314
Object {
315
"commitDurations": Array [
316
0,
292
- 2,
317
+ 0,
318
1,
319
+ 0,
320
2,
295
- 2,
296
- 2,
321
+ 0,
322
],
323
"fiberID": 3,
324
"rootID": 1,
@@ -303,10 +328,8 @@ Object {
328
exports[`profiling FiberCommits should be collected for each rendered fiber: FiberCommits: element 4 1`] = `
329
Object {
330
"commitDurations": Array [
331
+ 0,
332
1,
307
- 2,
308
- 2,
309
- 2,
333
],
334
"fiberID": 4,
335
"rootID": 1,
@@ -316,25 +339,40 @@ Object {
339
exports[`profiling FiberCommits should be collected for each rendered fiber: FiberCommits: element 5 1`] = `
340
Object {
341
"commitDurations": Array [
342
+ 1,
343
+ 1,
344
2,
320
- 2,
345
+ 1,
346
],
347
"fiberID": 5,
348
"rootID": 1,
349
}
350
`;
351
352
+exports[`profiling FiberCommits should be collected for each rendered fiber: FiberCommits: element 6 1`] = `
353
+Object {
354
+ "commitDurations": Array [
355
+ 2,
356
+ 2,
357
+ ],
358
+ "fiberID": 6,
359
+ "rootID": 1,
360
+}
361
+`;
362
+
363
exports[`profiling FiberCommits should be collected for each rendered fiber: exported data 1`] = `
364
Object {
365
"commitDetails": Array [
366
Object {
367
"actualDurations": Array [
368
1,
333
- 12,
369
+ 11,
370
2,
335
- 12,
371
+ 11,
372
3,
337
- 2,
373
+ 0,
374
+ 4,
375
+ 1,
376
],
377
"commitIndex": 0,
378
"interactions": Array [],
@@ -343,13 +381,13 @@ Object {
381
Object {
382
"actualDurations": Array [
383
3,
384
+ 0,
385
+ 5,
386
+ 1,
387
2,
347
- 4,
348
- 2,
349
- 2,
350
- 14,
388
+ 11,
389
1,
352
- 14,
390
+ 11,
391
],
392
"commitIndex": 1,
393
"interactions": Array [],
@@ -358,15 +396,15 @@ Object {
396
Object {
397
"actualDurations": Array [
398
3,
361
- 2,
362
- 4,
363
- 2,
399
+ 0,
400
5,
401
+ 1,
402
+ 6,
403
2,
404
2,
367
- 16,
405
+ 13,
406
1,
369
- 16,
407
+ 13,
408
],
409
"commitIndex": 2,
410
"interactions": Array [],
@@ -382,7 +420,7 @@ Object {
420
Array [
421
1,
422
1,
385
- 15,
423
+ 27,
424
6,
425
80,
426
97,
@@ -398,6 +436,18 @@ Object {
436
100,
437
1,
438
48,
439
+ 11,
440
+ 77,
441
+ 101,
442
+ 109,
443
+ 111,
444
+ 40,
445
+ 67,
446
+ 104,
447
+ 105,
448
+ 108,
449
+ 100,
450
+ 41,
451
1,
452
1,
453
11,
@@ -405,7 +455,7 @@ Object {
455
1,
456
4,
457
1,
408
- 12000,
458
+ 11000,
459
1,
460
2,
461
5,
@@ -415,7 +465,7 @@ Object {
465
0,
466
4,
467
2,
418
- 12000,
468
+ 11000,
469
1,
470
3,
471
5,
@@ -425,7 +475,17 @@ Object {
475
3,
476
4,
477
3,
428
- 2000,
478
+ 0,
479
+ 1,
480
+ 4,
481
+ 8,
482
+ 2,
483
+ 2,
484
+ 4,
485
+ 0,
486
+ 4,
487
+ 4,
488
+ 1000,
489
],
490
Array [
491
1,
@@ -440,26 +500,27 @@ Object {
500
1,
501
49,
502
1,
443
- 4,
503
+ 5,
504
5,
505
2,
506
2,
507
1,
508
2,
509
4,
450
- 4,
451
- 2000,
510
+ 5,
511
+ 1000,
512
4,
513
2,
454
- 14000,
514
+ 12000,
515
3,
516
2,
457
- 2,
517
3,
518
+ 3,
519
+ 5,
520
4,
521
4,
522
1,
462
- 14000,
523
+ 12000,
524
],
525
Array [
526
1,
@@ -474,27 +535,28 @@ Object {
535
1,
536
50,
537
1,
477
- 5,
538
+ 6,
539
5,
540
2,
541
2,
542
1,
543
2,
544
4,
484
- 5,
545
+ 6,
546
2000,
547
4,
548
2,
488
- 16000,
549
+ 14000,
550
3,
551
2,
491
- 3,
492
- 3,
552
4,
553
+ 3,
554
5,
555
+ 6,
556
+ 4,
557
4,
558
1,
497
- 16000,
559
+ 14000,
560
],
561
],
562
},
@@ -503,14 +565,14 @@ Object {
565
},
566
"profilingSummary": Object {
567
"commitDurations": Array [
506
- 12,
507
- 14,
508
- 16,
568
+ 11,
569
+ 11,
570
+ 13,
571
],
572
"commitTimes": Array [
511
- 12,
512
- 26,
513
- 42,
573
+ 11,
574
+ 22,
575
+ 35,
576
],
577
"initialTreeBaseDurations": Array [],
578
"interactionCount": 0,
@@ -538,7 +600,7 @@ Array [
600
],
601
"id": 1,
602
"name": "update: two children",
541
- "timestamp": 12,
603
+ "timestamp": 11,
604
},
605
]
606
`;
@@ -549,11 +611,13 @@ Object {
611
Object {
612
"actualDurations": Array [
613
1,
552
- 12,
614
+ 11,
615
2,
554
- 12,
616
+ 11,
617
3,
556
- 2,
618
+ 0,
619
+ 4,
620
+ 1,
621
],
622
"commitIndex": 0,
623
"interactions": Array [
@@ -569,13 +633,13 @@ Object {
633
Object {
634
"actualDurations": Array [
635
3,
636
+ 0,
637
+ 5,
638
+ 1,
639
2,
573
- 4,
574
- 2,
575
- 2,
576
- 14,
640
+ 11,
641
1,
578
- 14,
642
+ 11,
643
],
644
"commitIndex": 1,
645
"interactions": Array [
@@ -583,7 +647,7 @@ Object {
647
"__count": 0,
648
"id": 1,
649
"name": "update: two children",
586
- "timestamp": 12,
650
+ "timestamp": 11,
651
},
652
],
653
"rootID": 1,
@@ -607,7 +671,7 @@ Object {
671
],
672
"id": 1,
673
"name": "update: two children",
610
- "timestamp": 12,
674
+ "timestamp": 11,
675
},
676
],
677
"rootID": 1,
@@ -617,7 +681,7 @@ Object {
681
Array [
682
1,
683
1,
620
- 15,
684
+ 27,
685
6,
686
80,
687
97,
@@ -633,6 +697,18 @@ Object {
697
100,
698
1,
699
48,
700
+ 11,
701
+ 77,
702
+ 101,
703
+ 109,
704
+ 111,
705
+ 40,
706
+ 67,
707
+ 104,
708
+ 105,
709
+ 108,
710
+ 100,
711
+ 41,
712
1,
713
1,
714
11,
@@ -640,7 +716,7 @@ Object {
716
1,
717
4,
718
1,
643
- 12000,
719
+ 11000,
720
1,
721
2,
722
5,
@@ -650,7 +726,7 @@ Object {
726
0,
727
4,
728
2,
653
- 12000,
729
+ 11000,
730
1,
731
3,
732
5,
@@ -660,7 +736,17 @@ Object {
736
3,
737
4,
738
3,
663
- 2000,
739
+ 0,
740
+ 1,
741
+ 4,
742
+ 8,
743
+ 2,
744
+ 2,
745
+ 4,
746
+ 0,
747
+ 4,
748
+ 4,
749
+ 1000,
750
],
751
Array [
752
1,
@@ -675,26 +761,27 @@ Object {
761
1,
762
49,
763
1,
678
- 4,
764
+ 5,
765
5,
766
2,
767
2,
768
1,
769
2,
770
4,
685
- 4,
686
- 2000,
771
+ 5,
772
+ 1000,
773
4,
774
2,
689
- 14000,
775
+ 12000,
776
3,
777
2,
692
- 2,
778
3,
779
+ 3,
780
+ 5,
781
4,
782
4,
783
1,
697
- 14000,
784
+ 12000,
785
],
786
],
787
},
@@ -703,12 +790,12 @@ Object {
790
},
791
"profilingSummary": Object {
792
"commitDurations": Array [
706
- 12,
707
- 14,
793
+ 11,
794
+ 11,
795
],
796
"commitTimes": Array [
710
- 12,
711
- 26,
797
+ 11,
798
+ 22,
799
],
800
"initialTreeBaseDurations": Array [],
801
"interactionCount": 2,
@@ -721,20 +808,21 @@ Object {
808
exports[`profiling ProfilingSummary should be collected for each commit: ProfilingSummary 1`] = `
809
Object {
810
"commitDurations": Array [
724
- 16,
725
- 12,
811
+ 13,
812
+ 10,
813
10,
814
],
815
"commitTimes": Array [
729
- 16,
730
- 28,
731
- 38,
816
+ 13,
817
+ 23,
818
+ 33,
819
],
820
"initialTreeBaseDurations": Map {
734
- 1 => 14,
735
- 2 => 14,
736
- 3 => 2,
737
- 4 => 2,
821
+ 1 => 12,
822
+ 2 => 12,
823
+ 3 => 0,
824
+ 4 => 1,
825
+ 5 => 1,
826
},
827
"interactionCount": 0,
828
"rootID": 1,
@@ -747,15 +835,15 @@ Object {
835
Object {
836
"actualDurations": Array [
837
3,
750
- 2,
838
+ 0,
839
4,
752
- 2,
753
- 5,
840
+ 1,
841
+ 6,
842
2,
843
2,
756
- 16,
844
+ 13,
845
1,
758
- 16,
846
+ 13,
847
],
848
"commitIndex": 0,
849
"interactions": Array [],
@@ -764,11 +852,11 @@ Object {
852
Object {
853
"actualDurations": Array [
854
3,
855
+ 0,
856
2,
768
- 2,
769
- 12,
857
+ 10,
858
1,
771
- 12,
859
+ 10,
860
],
861
"commitIndex": 1,
862
"interactions": Array [],
@@ -805,27 +893,28 @@ Object {
893
1,
894
50,
895
1,
808
- 5,
896
+ 6,
897
5,
898
2,
899
2,
900
1,
901
2,
902
4,
815
- 5,
903
+ 6,
904
2000,
905
4,
906
2,
819
- 16000,
907
+ 14000,
908
3,
909
2,
822
- 3,
910
+ 4,
911
3,
912
4,
913
+ 6,
914
5,
915
4,
916
1,
828
- 16000,
917
+ 14000,
918
],
919
Array [
920
1,
@@ -833,14 +922,19 @@ Object {
922
0,
923
2,
924
2,
836
- 5,
925
+ 6,
926
4,
927
4,
928
2,
840
- 12000,
929
+ 11000,
930
+ 3,
931
+ 2,
932
+ 2,
933
+ 3,
934
+ 5,
935
4,
936
1,
843
- 12000,
937
+ 11000,
938
],
939
Array [
940
1,
@@ -849,12 +943,6 @@ Object {
943
2,
944
1,
945
3,
852
- 4,
853
- 2,
854
- 10000,
855
- 4,
856
- 1,
857
- 10000,
946
],
947
],
948
},
@@ -872,6 +960,7 @@ Object {
960
"children": Array [
961
3,
962
4,
963
+ 5,
964
],
965
"displayName": "Parent",
966
"id": 2,
@@ -889,28 +978,36 @@ Object {
978
"id": 4,
979
"key": "1",
980
},
981
+ 5 => Object {
982
+ "children": Array [],
983
+ "displayName": "Memo(Child)",
984
+ "id": 5,
985
+ "key": null,
986
+ },
987
},
988
},
989
"profilingSummary": Object {
990
"commitDurations": Array [
896
- 16,
897
- 12,
991
+ 13,
992
+ 10,
993
10,
994
],
995
"commitTimes": Array [
901
- 16,
902
- 28,
903
- 38,
996
+ 13,
997
+ 23,
998
+ 33,
999
],
1000
"initialTreeBaseDurations": Array [
1001
1,
907
- 14,
1002
+ 12,
1003
2,
909
- 14,
1004
+ 12,
1005
3,
911
- 2,
1006
+ 0,
1007
4,
913
- 2,
1008
+ 1,
1009
+ 5,
1010
+ 1,
1011
],
1012
"interactionCount": 0,
1013
"rootID": 1,
src/__tests__/__snapshots__/profilingCharts-test.js.snap
+8
-2
@@ -81,9 +81,9 @@ Object {
81
Array [
82
Object {
83
"actualDuration": 0,
84
- "didRender": false,
84
+ "didRender": true,
85
"id": 5,
86
- "label": "Memo(Child) key=\\"third\\"",
86
+ "label": "Memo(Child) key=\\"third\\" (<0.1ms of <0.1ms)",
87
"name": "Memo(Child)",
88
"offset": 15,
89
"selfDuration": 0,
@@ -318,6 +318,12 @@ Object {
318
"name": "Memo(Child)",
319
"value": 2,
320
},
321
+ Object {
322
+ "id": 5,
323
+ "label": "Memo(Child) key=\\"third\\" (<0.1ms)",
324
+ "name": "Memo(Child)",
325
+ "value": 0,
326
+ },
327
],
328
}
329
`;
src/__tests__/profiling-test.js
+47
-17
@@ -86,14 +86,21 @@ describe('profiling', () => {
86
it('should be collected for each commit', async done => {
87
const Parent = ({ count }) => {
88
Scheduler.advanceTime(10);
89
- return new Array(count)
89
+ const children = new Array(count)
90
.fill(true)
91
- .map((_, index) => <Child key={index} />);
91
+ .map((_, index) => <Child key={index} duration={index} />);
92
+ return (
93
+ <React.Fragment>
94
+ {children}
95
+ <MemoizedChild duration={1} />
96
+ </React.Fragment>
97
+ );
98
};
93
- const Child = () => {
94
- Scheduler.advanceTime(2);
99
+ const Child = ({ duration }) => {
100
+ Scheduler.advanceTime(duration);
101
return null;
102
};
103
+ const MemoizedChild = React.memo(Child);
104
105
const container = document.createElement('div');
106
@@ -158,14 +165,21 @@ describe('profiling', () => {
165
it('should be collected for each commit', async done => {
166
const Parent = ({ count }) => {
167
Scheduler.advanceTime(10);
161
- return new Array(count)
168
+ const children = new Array(count)
169
.fill(true)
163
- .map((_, index) => <Child key={index} />);
170
+ .map((_, index) => <Child key={index} duration={index} />);
171
+ return (
172
+ <React.Fragment>
173
+ {children}
174
+ <MemoizedChild duration={1} />
175
+ </React.Fragment>
176
+ );
177
};
165
- const Child = () => {
166
- Scheduler.advanceTime(2);
178
+ const Child = ({ duration }) => {
179
+ Scheduler.advanceTime(duration);
180
return null;
181
};
182
+ const MemoizedChild = React.memo(Child);
183
184
const container = document.createElement('div');
185
@@ -245,14 +259,21 @@ describe('profiling', () => {
259
it('should be collected for each rendered fiber', async done => {
260
const Parent = ({ count }) => {
261
Scheduler.advanceTime(10);
248
- return new Array(count)
262
+ const children = new Array(count)
263
.fill(true)
250
- .map((_, index) => <Child key={index} />);
264
+ .map((_, index) => <Child key={index} duration={index} />);
265
+ return (
266
+ <React.Fragment>
267
+ {children}
268
+ <MemoizedChild duration={1} />
269
+ </React.Fragment>
270
+ );
271
};
252
- const Child = () => {
253
- Scheduler.advanceTime(2);
272
+ const Child = ({ duration }) => {
273
+ Scheduler.advanceTime(duration);
274
return null;
275
};
276
+ const MemoizedChild = React.memo(Child);
277
278
const container = document.createElement('div');
279
@@ -339,14 +360,21 @@ describe('profiling', () => {
360
it('should be collected for every traced interaction', async done => {
361
const Parent = ({ count }) => {
362
Scheduler.advanceTime(10);
342
- return new Array(count)
363
+ const children = new Array(count)
364
.fill(true)
344
- .map((_, index) => <Child key={index} />);
365
+ .map((_, index) => <Child key={index} duration={index} />);
366
+ return (
367
+ <React.Fragment>
368
+ {children}
369
+ <MemoizedChild duration={1} />
370
+ </React.Fragment>
371
+ );
372
};
346
- const Child = () => {
347
- Scheduler.advanceTime(2);
373
+ const Child = ({ duration }) => {
374
+ Scheduler.advanceTime(duration);
375
return null;
376
};
377
+ const MemoizedChild = React.memo(Child);
378
379
const container = document.createElement('div');
380
@@ -419,7 +447,9 @@ describe('profiling', () => {
447
448
it('should remove profiling data when roots are unmounted', async () => {
449
const Parent = ({ count }) =>
422
- new Array(count).fill(true).map((_, index) => <Child key={index} />);
450
+ new Array(count)
451
+ .fill(true)
452
+ .map((_, index) => <Child key={index} duration={index} />);
453
const Child = () => <div>Hi!</div>;
454
455
const containerA = document.createElement('div');
src/backend/renderer.js
+7
-15
@@ -645,18 +645,6 @@ export function attach(
645
}
646
}
647
648
- function haveProfilerTimesChanged(
649
- prevFiber: Fiber,
650
- nextFiber: Fiber
651
- ): boolean {
652
- return (
653
- prevFiber.actualDuration !== undefined && // Short-circuit check for non-profiling builds
654
- (prevFiber.actualDuration !== nextFiber.actualDuration ||
655
- prevFiber.actualStartTime !== nextFiber.actualStartTime ||
656
- prevFiber.treeBaseDuration !== nextFiber.treeBaseDuration)
657
- );
658
- }
659
-
648
let pendingOperations: Array<number> = [];
649
let pendingRealUnmountedIDs: Array<number> = [];
650
let pendingSimulatedUnmountedIDs: Array<number> = [];
@@ -843,8 +831,9 @@ export function attach(
831
pushOperation(treeBaseDuration);
832
833
const { actualDuration } = fiber;
846
- if (actualDuration != null && actualDuration > 0) {
834
+ if (actualDuration != null) {
835
// If profiling is active, store durations for elements that were rendered during the commit.
836
+ // We should do this for all fibers on mount, regardless of their actual durations.
837
const metadata = ((currentCommitProfilingMetadata: any): CommitProfilingData);
838
metadata.actualDurations.push(id, actualDuration);
839
metadata.maxActualDuration = Math.max(
@@ -1024,9 +1013,12 @@ export function attach(
1013
pushOperation(treeBaseDuration);
1014
}
1015
1027
- if (alternate ? haveProfilerTimesChanged(alternate, fiber) : true) {
1028
- if (actualDuration != null && actualDuration > 0) {
1016
+ if (alternate ? hasDataChanged(alternate, fiber) : true) {
1017
+ if (actualDuration != null) {
1018
// If profiling is active, store durations for elements that were rendered during the commit.
1019
+ // Note that we should do this for any fiber we performed work on, regardless of its actualDuration value.
1020
+ // In some cases actualDuration might be 0 for fibers we worked on (particularly if we're using Date.now)
1021
+ // In other cases (e.g. Memo) actualDuration might be greater than 0 even if we "bailed out".
1022
const metadata = ((currentCommitProfilingMetadata: any): CommitProfilingData);
1023
metadata.actualDurations.push(id, actualDuration);
1024
metadata.maxActualDuration = Math.max(