@@ -2896,6 +2896,7 @@ function commitPassiveMountOnFiber(
2896
2896
finishedWork ,
2897
2897
committedLanes ,
2898
2898
committedTransitions ,
2899
+ endTime ,
2899
2900
) ;
2900
2901
}
2901
2902
} else {
@@ -2935,6 +2936,7 @@ function commitPassiveMountOnFiber(
2935
2936
committedLanes ,
2936
2937
committedTransitions ,
2937
2938
includeWorkInProgressEffects ,
2939
+ endTime ,
2938
2940
) ;
2939
2941
}
2940
2942
}
@@ -3014,6 +3016,7 @@ function recursivelyTraverseReconnectPassiveEffects(
3014
3016
committedLanes : Lanes ,
3015
3017
committedTransitions : Array < Transition > | null ,
3016
3018
includeWorkInProgressEffects : boolean ,
3019
+ endTime : number ,
3017
3020
) {
3018
3021
// This function visits both newly finished work and nodes that were re-used
3019
3022
// from a previously committed tree. We cannot check non-static flags if the
@@ -3025,14 +3028,30 @@ function recursivelyTraverseReconnectPassiveEffects(
3025
3028
// TODO (Offscreen) Check: flags & (RefStatic | LayoutStatic)
3026
3029
let child = parentFiber . child ;
3027
3030
while ( child !== null ) {
3028
- reconnectPassiveEffects (
3029
- finishedRoot ,
3030
- child ,
3031
- committedLanes ,
3032
- committedTransitions ,
3033
- childShouldIncludeWorkInProgressEffects ,
3034
- ) ;
3035
- child = child . sibling ;
3031
+ if ( enableProfilerTimer && enableComponentPerformanceTrack ) {
3032
+ const nextSibling = child . sibling ;
3033
+ reconnectPassiveEffects (
3034
+ finishedRoot ,
3035
+ child ,
3036
+ committedLanes ,
3037
+ committedTransitions ,
3038
+ childShouldIncludeWorkInProgressEffects ,
3039
+ nextSibling !== null
3040
+ ? ( ( nextSibling . actualStartTime : any ) : number )
3041
+ : endTime ,
3042
+ ) ;
3043
+ child = nextSibling ;
3044
+ } else {
3045
+ reconnectPassiveEffects (
3046
+ finishedRoot ,
3047
+ child ,
3048
+ committedLanes ,
3049
+ committedTransitions ,
3050
+ childShouldIncludeWorkInProgressEffects ,
3051
+ endTime ,
3052
+ ) ;
3053
+ child = child . sibling ;
3054
+ }
3036
3055
}
3037
3056
}
3038
3057
@@ -3045,9 +3064,28 @@ export function reconnectPassiveEffects(
3045
3064
// from a previously committed tree. We cannot check non-static flags if the
3046
3065
// node was reused.
3047
3066
includeWorkInProgressEffects : boolean ,
3067
+ endTime : number , // Profiling-only. The start time of the next Fiber or root completion.
3048
3068
) {
3049
3069
const prevEffectStart = pushComponentEffectStart ( ) ;
3050
3070
3071
+ // If this component rendered in Profiling mode (DEV or in Profiler component) then log its
3072
+ // render time. We do this after the fact in the passive effect to avoid the overhead of this
3073
+ // getting in the way of the render characteristics and avoid the overhead of unwinding
3074
+ // uncommitted renders.
3075
+ if (
3076
+ enableProfilerTimer &&
3077
+ enableComponentPerformanceTrack &&
3078
+ ( finishedWork . mode & ProfileMode ) !== NoMode &&
3079
+ ( ( finishedWork . actualStartTime : any ) : number ) > 0 &&
3080
+ ( finishedWork . flags & PerformedWork ) !== NoFlags
3081
+ ) {
3082
+ logComponentRender (
3083
+ finishedWork ,
3084
+ ( ( finishedWork . actualStartTime : any ) : number ) ,
3085
+ endTime ,
3086
+ ) ;
3087
+ }
3088
+
3051
3089
const flags = finishedWork . flags ;
3052
3090
switch ( finishedWork . tag ) {
3053
3091
case FunctionComponent :
@@ -3059,6 +3097,7 @@ export function reconnectPassiveEffects(
3059
3097
committedLanes ,
3060
3098
committedTransitions ,
3061
3099
includeWorkInProgressEffects ,
3100
+ endTime ,
3062
3101
) ;
3063
3102
// TODO: Check for PassiveStatic flag
3064
3103
commitHookPassiveMountEffects ( finishedWork , HookPassive ) ;
@@ -3078,6 +3117,7 @@ export function reconnectPassiveEffects(
3078
3117
committedLanes ,
3079
3118
committedTransitions ,
3080
3119
includeWorkInProgressEffects ,
3120
+ endTime ,
3081
3121
) ;
3082
3122
3083
3123
if ( includeWorkInProgressEffects && flags & Passive ) {
@@ -3104,6 +3144,7 @@ export function reconnectPassiveEffects(
3104
3144
committedLanes ,
3105
3145
committedTransitions ,
3106
3146
includeWorkInProgressEffects ,
3147
+ endTime ,
3107
3148
) ;
3108
3149
} else {
3109
3150
if ( disableLegacyMode || finishedWork . mode & ConcurrentMode ) {
@@ -3118,6 +3159,7 @@ export function reconnectPassiveEffects(
3118
3159
finishedWork ,
3119
3160
committedLanes ,
3120
3161
committedTransitions ,
3162
+ endTime ,
3121
3163
) ;
3122
3164
}
3123
3165
} else {
@@ -3129,6 +3171,7 @@ export function reconnectPassiveEffects(
3129
3171
committedLanes ,
3130
3172
committedTransitions ,
3131
3173
includeWorkInProgressEffects ,
3174
+ endTime ,
3132
3175
) ;
3133
3176
}
3134
3177
}
@@ -3148,6 +3191,7 @@ export function reconnectPassiveEffects(
3148
3191
committedLanes ,
3149
3192
committedTransitions ,
3150
3193
includeWorkInProgressEffects ,
3194
+ endTime ,
3151
3195
) ;
3152
3196
}
3153
3197
@@ -3165,6 +3209,7 @@ export function reconnectPassiveEffects(
3165
3209
committedLanes ,
3166
3210
committedTransitions ,
3167
3211
includeWorkInProgressEffects ,
3212
+ endTime ,
3168
3213
) ;
3169
3214
if ( includeWorkInProgressEffects && flags & Passive ) {
3170
3215
// TODO: Pass `current` as argument to this function
@@ -3181,6 +3226,7 @@ export function reconnectPassiveEffects(
3181
3226
committedLanes ,
3182
3227
committedTransitions ,
3183
3228
includeWorkInProgressEffects ,
3229
+ endTime ,
3184
3230
) ;
3185
3231
if ( includeWorkInProgressEffects && flags & Passive ) {
3186
3232
commitTracingMarkerPassiveMountEffect ( finishedWork ) ;
@@ -3196,6 +3242,7 @@ export function reconnectPassiveEffects(
3196
3242
committedLanes ,
3197
3243
committedTransitions ,
3198
3244
includeWorkInProgressEffects ,
3245
+ endTime ,
3199
3246
) ;
3200
3247
break ;
3201
3248
}
@@ -3226,6 +3273,7 @@ function recursivelyTraverseAtomicPassiveEffects(
3226
3273
parentFiber : Fiber ,
3227
3274
committedLanes : Lanes ,
3228
3275
committedTransitions : Array < Transition > | null ,
3276
+ endTime : number , // Profiling-only. The start time of the next Fiber or root completion.
3229
3277
) {
3230
3278
// "Atomic" effects are ones that need to fire on every commit, even during
3231
3279
// pre-rendering. We call this function when traversing a hidden tree whose
@@ -3234,13 +3282,28 @@ function recursivelyTraverseAtomicPassiveEffects(
3234
3282
if ( parentFiber . subtreeFlags & PassiveMask ) {
3235
3283
let child = parentFiber . child ;
3236
3284
while ( child !== null ) {
3237
- commitAtomicPassiveEffects (
3238
- finishedRoot ,
3239
- child ,
3240
- committedLanes ,
3241
- committedTransitions ,
3242
- ) ;
3243
- child = child . sibling ;
3285
+ if ( enableProfilerTimer && enableComponentPerformanceTrack ) {
3286
+ const nextSibling = child . sibling ;
3287
+ commitAtomicPassiveEffects (
3288
+ finishedRoot ,
3289
+ child ,
3290
+ committedLanes ,
3291
+ committedTransitions ,
3292
+ nextSibling !== null
3293
+ ? ( ( nextSibling . actualStartTime : any ) : number )
3294
+ : endTime ,
3295
+ ) ;
3296
+ child = nextSibling ;
3297
+ } else {
3298
+ commitAtomicPassiveEffects (
3299
+ finishedRoot ,
3300
+ child ,
3301
+ committedLanes ,
3302
+ committedTransitions ,
3303
+ endTime ,
3304
+ ) ;
3305
+ child = child . sibling ;
3306
+ }
3244
3307
}
3245
3308
}
3246
3309
}
@@ -3250,7 +3313,24 @@ function commitAtomicPassiveEffects(
3250
3313
finishedWork : Fiber ,
3251
3314
committedLanes : Lanes ,
3252
3315
committedTransitions : Array < Transition > | null ,
3316
+ endTime : number , // Profiling-only. The start time of the next Fiber or root completion.
3253
3317
) {
3318
+ // If this component rendered in Profiling mode (DEV or in Profiler component) then log its
3319
+ // render time. A render can happen even if the subtree is offscreen.
3320
+ if (
3321
+ enableProfilerTimer &&
3322
+ enableComponentPerformanceTrack &&
3323
+ ( finishedWork . mode & ProfileMode ) !== NoMode &&
3324
+ ( ( finishedWork . actualStartTime : any ) : number ) > 0 &&
3325
+ ( finishedWork . flags & PerformedWork ) !== NoFlags
3326
+ ) {
3327
+ logComponentRender (
3328
+ finishedWork ,
3329
+ ( ( finishedWork . actualStartTime : any ) : number ) ,
3330
+ endTime ,
3331
+ ) ;
3332
+ }
3333
+
3254
3334
// "Atomic" effects are ones that need to fire on every commit, even during
3255
3335
// pre-rendering. We call this function when traversing a hidden tree whose
3256
3336
// regular effects are currently disconnected.
@@ -3262,6 +3342,7 @@ function commitAtomicPassiveEffects(
3262
3342
finishedWork ,
3263
3343
committedLanes ,
3264
3344
committedTransitions ,
3345
+ endTime ,
3265
3346
) ;
3266
3347
if ( flags & Passive ) {
3267
3348
// TODO: Pass `current` as argument to this function
@@ -3277,6 +3358,7 @@ function commitAtomicPassiveEffects(
3277
3358
finishedWork ,
3278
3359
committedLanes ,
3279
3360
committedTransitions ,
3361
+ endTime ,
3280
3362
) ;
3281
3363
if ( flags & Passive ) {
3282
3364
// TODO: Pass `current` as argument to this function
@@ -3291,6 +3373,7 @@ function commitAtomicPassiveEffects(
3291
3373
finishedWork ,
3292
3374
committedLanes ,
3293
3375
committedTransitions ,
3376
+ endTime ,
3294
3377
) ;
3295
3378
break ;
3296
3379
}
0 commit comments