@@ -99,13 +99,21 @@ import {
99
99
Cloned ,
100
100
} from './ReactFiberFlags' ;
101
101
import {
102
- getCommitTime ,
103
- getCompleteTime ,
102
+ commitTime ,
103
+ completeTime ,
104
104
pushNestedEffectDurations ,
105
105
popNestedEffectDurations ,
106
106
bubbleNestedEffectDurations ,
107
+ resetComponentEffectTimers ,
108
+ pushComponentEffectStart ,
109
+ popComponentEffectStart ,
110
+ componentEffectStartTime ,
111
+ componentEffectEndTime ,
107
112
} from './ReactProfilerTimer' ;
108
- import { logComponentRender } from './ReactFiberPerformanceTrack' ;
113
+ import {
114
+ logComponentRender ,
115
+ logComponentEffect ,
116
+ } from './ReactFiberPerformanceTrack' ;
109
117
import { ConcurrentMode , NoMode , ProfileMode } from './ReactTypeOfMode' ;
110
118
import { deferHiddenCallbacks } from './ReactFiberClassUpdateQueue' ;
111
119
import {
@@ -382,6 +390,8 @@ function commitLayoutEffectOnFiber(
382
390
finishedWork : Fiber ,
383
391
committedLanes : Lanes ,
384
392
) : void {
393
+ const prevEffectStart = pushComponentEffectStart ( ) ;
394
+
385
395
// When updating this function, also update reappearLayoutEffects, which does
386
396
// most of the same things when an offscreen tree goes from hidden -> visible.
387
397
const flags = finishedWork . flags ;
@@ -494,7 +504,7 @@ function commitLayoutEffectOnFiber(
494
504
commitProfilerUpdate (
495
505
finishedWork ,
496
506
current ,
497
- getCommitTime ( ) ,
507
+ commitTime ,
498
508
profilerInstance . effectDuration ,
499
509
) ;
500
510
} else {
@@ -585,6 +595,23 @@ function commitLayoutEffectOnFiber(
585
595
break ;
586
596
}
587
597
}
598
+
599
+ if (
600
+ enableProfilerTimer &&
601
+ enableProfilerCommitHooks &&
602
+ enableComponentPerformanceTrack &&
603
+ ( finishedWork . mode & ProfileMode ) !== NoMode &&
604
+ componentEffectStartTime >= 0 &&
605
+ componentEffectEndTime >= 0
606
+ ) {
607
+ logComponentEffect (
608
+ finishedWork ,
609
+ componentEffectStartTime ,
610
+ componentEffectEndTime ,
611
+ ) ;
612
+ }
613
+
614
+ popComponentEffectStart ( prevEffectStart ) ;
588
615
}
589
616
590
617
function abortRootTransitions (
@@ -1530,6 +1557,8 @@ export function commitMutationEffects(
1530
1557
inProgressLanes = committedLanes ;
1531
1558
inProgressRoot = root ;
1532
1559
1560
+ resetComponentEffectTimers ( ) ;
1561
+
1533
1562
commitMutationEffectsOnFiber ( finishedWork , root , committedLanes ) ;
1534
1563
1535
1564
inProgressLanes = null ;
@@ -1570,6 +1599,8 @@ function commitMutationEffectsOnFiber(
1570
1599
root : FiberRoot ,
1571
1600
lanes : Lanes ,
1572
1601
) {
1602
+ const prevEffectStart = pushComponentEffectStart ( ) ;
1603
+
1573
1604
const current = finishedWork . alternate ;
1574
1605
const flags = finishedWork . flags ;
1575
1606
@@ -1598,7 +1629,7 @@ function commitMutationEffectsOnFiber(
1598
1629
HookLayout | HookHasEffect ,
1599
1630
) ;
1600
1631
}
1601
- return ;
1632
+ break ;
1602
1633
}
1603
1634
case ClassComponent : {
1604
1635
recursivelyTraverseMutationEffects ( root , finishedWork , lanes ) ;
@@ -1617,7 +1648,7 @@ function commitMutationEffectsOnFiber(
1617
1648
deferHiddenCallbacks ( updateQueue ) ;
1618
1649
}
1619
1650
}
1620
- return ;
1651
+ break ;
1621
1652
}
1622
1653
case HostHoistable : {
1623
1654
if ( supportsResources ) {
@@ -1693,7 +1724,7 @@ function commitMutationEffectsOnFiber(
1693
1724
) ;
1694
1725
}
1695
1726
}
1696
- return ;
1727
+ break ;
1697
1728
}
1698
1729
// Fall through
1699
1730
}
@@ -1756,7 +1787,7 @@ function commitMutationEffectsOnFiber(
1756
1787
}
1757
1788
}
1758
1789
}
1759
- return ;
1790
+ break ;
1760
1791
}
1761
1792
case HostText : {
1762
1793
recursivelyTraverseMutationEffects ( root , finishedWork , lanes ) ;
@@ -1781,7 +1812,7 @@ function commitMutationEffectsOnFiber(
1781
1812
commitHostTextUpdate ( finishedWork , newText , oldText ) ;
1782
1813
}
1783
1814
}
1784
- return ;
1815
+ break ;
1785
1816
}
1786
1817
case HostRoot : {
1787
1818
const prevEffectDuration = pushNestedEffectDurations ( ) ;
@@ -1833,7 +1864,7 @@ function commitMutationEffectsOnFiber(
1833
1864
root . effectDuration += popNestedEffectDurations ( prevEffectDuration ) ;
1834
1865
}
1835
1866
1836
- return ;
1867
+ break ;
1837
1868
}
1838
1869
case HostPortal : {
1839
1870
if ( supportsResources ) {
@@ -1858,7 +1889,7 @@ function commitMutationEffectsOnFiber(
1858
1889
) ;
1859
1890
}
1860
1891
}
1861
- return ;
1892
+ break ;
1862
1893
}
1863
1894
case Profiler : {
1864
1895
const prevEffectDuration = pushNestedEffectDurations ( ) ;
@@ -1873,7 +1904,7 @@ function commitMutationEffectsOnFiber(
1873
1904
profilerInstance . effectDuration +=
1874
1905
bubbleNestedEffectDurations ( prevEffectDuration ) ;
1875
1906
}
1876
- return ;
1907
+ break ;
1877
1908
}
1878
1909
case SuspenseComponent : {
1879
1910
recursivelyTraverseMutationEffects ( root , finishedWork , lanes ) ;
@@ -1925,7 +1956,7 @@ function commitMutationEffectsOnFiber(
1925
1956
attachSuspenseRetryListeners ( finishedWork , retryQueue ) ;
1926
1957
}
1927
1958
}
1928
- return ;
1959
+ break ;
1929
1960
}
1930
1961
case OffscreenComponent : {
1931
1962
if ( flags & Ref ) {
@@ -2018,7 +2049,7 @@ function commitMutationEffectsOnFiber(
2018
2049
}
2019
2050
}
2020
2051
}
2021
- return ;
2052
+ break ;
2022
2053
}
2023
2054
case SuspenseListComponent : {
2024
2055
recursivelyTraverseMutationEffects ( root , finishedWork , lanes ) ;
@@ -2032,7 +2063,7 @@ function commitMutationEffectsOnFiber(
2032
2063
attachSuspenseRetryListeners ( finishedWork , retryQueue ) ;
2033
2064
}
2034
2065
}
2035
- return ;
2066
+ break ;
2036
2067
}
2037
2068
case ScopeComponent: {
2038
2069
if ( enableScopeAPI ) {
@@ -2052,16 +2083,34 @@ function commitMutationEffectsOnFiber(
2052
2083
prepareScopeUpdate ( scopeInstance , finishedWork ) ;
2053
2084
}
2054
2085
}
2055
- return ;
2086
+ break ;
2056
2087
}
2057
2088
default: {
2058
2089
recursivelyTraverseMutationEffects ( root , finishedWork , lanes ) ;
2059
2090
commitReconciliationEffects ( finishedWork ) ;
2060
2091
2061
- return ;
2092
+ break ;
2062
2093
}
2063
2094
}
2095
+
2096
+ if (
2097
+ enableProfilerTimer &&
2098
+ enableProfilerCommitHooks &&
2099
+ enableComponentPerformanceTrack &&
2100
+ ( finishedWork . mode & ProfileMode ) !== NoMode &&
2101
+ componentEffectStartTime >= 0 &&
2102
+ componentEffectEndTime >= 0
2103
+ ) {
2104
+ logComponentEffect (
2105
+ finishedWork ,
2106
+ componentEffectStartTime ,
2107
+ componentEffectEndTime ,
2108
+ ) ;
2109
+ }
2110
+
2111
+ popComponentEffectStart ( prevEffectStart ) ;
2064
2112
}
2113
+
2065
2114
function commitReconciliationEffects ( finishedWork : Fiber ) {
2066
2115
// Placement effects (insertions, reorders) can be scheduled on any fiber
2067
2116
// type. They needs to happen after the children effects have fired, but
@@ -2106,6 +2155,8 @@ export function commitLayoutEffects(
2106
2155
inProgressLanes = committedLanes ;
2107
2156
inProgressRoot = root ;
2108
2157
2158
+ resetComponentEffectTimers ( ) ;
2159
+
2109
2160
const current = finishedWork . alternate ;
2110
2161
commitLayoutEffectOnFiber ( root , current , finishedWork , committedLanes ) ;
2111
2162
@@ -2291,7 +2342,7 @@ export function reappearLayoutEffects(
2291
2342
commitProfilerUpdate (
2292
2343
finishedWork ,
2293
2344
current ,
2294
- getCommitTime ( ) ,
2345
+ commitTime ,
2295
2346
profilerInstance . effectDuration ,
2296
2347
) ;
2297
2348
} else {
@@ -2515,14 +2566,14 @@ export function commitPassiveMountEffects(
2515
2566
committedLanes : Lanes ,
2516
2567
committedTransitions : Array < Transition > | null ,
2517
2568
) : void {
2569
+ resetComponentEffectTimers ( ) ;
2570
+
2518
2571
commitPassiveMountOnFiber (
2519
2572
root ,
2520
2573
finishedWork ,
2521
2574
committedLanes ,
2522
2575
committedTransitions ,
2523
- enableProfilerTimer && enableComponentPerformanceTrack
2524
- ? getCompleteTime ( )
2525
- : 0 ,
2576
+ enableProfilerTimer && enableComponentPerformanceTrack ? completeTime : 0 ,
2526
2577
) ;
2527
2578
}
2528
2579
@@ -2577,6 +2628,8 @@ function commitPassiveMountOnFiber(
2577
2628
committedTransitions : Array < Transition > | null ,
2578
2629
endTime : number , // Profiling-only. The start time of the next Fiber or root completion.
2579
2630
) : void {
2631
+ const prevEffectStart = pushComponentEffectStart ( ) ;
2632
+
2580
2633
// If this component rendered in Profiling mode (DEV or in Profiler component) then log its
2581
2634
// render time. We do this after the fact in the passive effect to avoid the overhead of this
2582
2635
// getting in the way of the render characteristics and avoid the overhead of unwinding
@@ -2707,7 +2760,7 @@ function commitPassiveMountOnFiber(
2707
2760
finishedWork . alternate ,
2708
2761
// This value will still reflect the previous commit phase.
2709
2762
// It does not get reset until the start of the next commit phase.
2710
- getCommitTime ( ) ,
2763
+ commitTime ,
2711
2764
profilerInstance . passiveEffectDuration ,
2712
2765
) ;
2713
2766
} else {
@@ -2860,6 +2913,23 @@ function commitPassiveMountOnFiber(
2860
2913
break ;
2861
2914
}
2862
2915
}
2916
+
2917
+ if (
2918
+ enableProfilerTimer &&
2919
+ enableProfilerCommitHooks &&
2920
+ enableComponentPerformanceTrack &&
2921
+ ( finishedWork . mode & ProfileMode ) !== NoMode &&
2922
+ componentEffectStartTime >= 0 &&
2923
+ componentEffectEndTime >= 0
2924
+ ) {
2925
+ logComponentEffect (
2926
+ finishedWork ,
2927
+ componentEffectStartTime ,
2928
+ componentEffectEndTime ,
2929
+ ) ;
2930
+ }
2931
+
2932
+ popComponentEffectStart ( prevEffectStart ) ;
2863
2933
}
2864
2934
2865
2935
function recursivelyTraverseReconnectPassiveEffects (
@@ -3131,6 +3201,7 @@ function commitAtomicPassiveEffects(
3131
3201
}
3132
3202
3133
3203
export function commitPassiveUnmountEffects ( finishedWork : Fiber ) : void {
3204
+ resetComponentEffectTimers ( ) ;
3134
3205
commitPassiveUnmountOnFiber ( finishedWork ) ;
3135
3206
}
3136
3207
@@ -3289,6 +3360,8 @@ function recursivelyTraversePassiveUnmountEffects(parentFiber: Fiber): void {
3289
3360
}
3290
3361
3291
3362
function commitPassiveUnmountOnFiber ( finishedWork : Fiber ) : void {
3363
+ const prevEffectStart = pushComponentEffectStart ( ) ;
3364
+
3292
3365
switch ( finishedWork . tag ) {
3293
3366
case FunctionComponent :
3294
3367
case ForwardRef :
@@ -3358,6 +3431,23 @@ function commitPassiveUnmountOnFiber(finishedWork: Fiber): void {
3358
3431
break ;
3359
3432
}
3360
3433
}
3434
+
3435
+ if (
3436
+ enableProfilerTimer &&
3437
+ enableProfilerCommitHooks &&
3438
+ enableComponentPerformanceTrack &&
3439
+ ( finishedWork . mode & ProfileMode ) !== NoMode &&
3440
+ componentEffectStartTime >= 0 &&
3441
+ componentEffectEndTime >= 0
3442
+ ) {
3443
+ logComponentEffect (
3444
+ finishedWork ,
3445
+ componentEffectStartTime ,
3446
+ componentEffectEndTime ,
3447
+ ) ;
3448
+ }
3449
+
3450
+ popComponentEffectStart ( prevEffectStart ) ;
3361
3451
}
3362
3452
3363
3453
function recursivelyTraverseDisconnectPassiveEffects ( parentFiber : Fiber ) : void {
0 commit comments