Skip to content

Commit 227a65a

Browse files
author
Brian Vaughn
committed
Add Lane labels to scheduling profiler marks
This changes profiler marks from a format like "--schedule-render-1" like "--schedule-render-1-Sync" which will enable the profiler itself to show more meaningful labels for updates and render work. There are a couple of downsides to this proposed change: 1. It reqiures maintaining a map of bitmask range to string/label in ReactFiberLanel. Hopefully not a huge burden but something we would need to remember to keep in sync. 2. It increases the size of User Timing data logged by the profiler during render. (I don't think there's a way around this since there's no initialization event where we can log a standalone mapping). Perhaps we could log a mapping with each commit or something but that doesn't seem like an obvious improvement.
1 parent 483358c commit 227a65a

File tree

4 files changed

+199
-66
lines changed

4 files changed

+199
-66
lines changed

packages/react-reconciler/src/ReactFiberLane.new.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import invariant from 'shared/invariant';
3939
import {
4040
enableCache,
4141
enableNonInterruptingNormalPri,
42+
enableSchedulingProfiler,
4243
} from 'shared/ReactFeatureFlags';
4344

4445
import {
@@ -127,6 +128,52 @@ const IdleLane: Lanes = /* */ 0b0100000000000000000
127128

128129
export const OffscreenLane: Lane = /* */ 0b1000000000000000000000000000000;
129130

131+
export function getLabelsForLanes(lanes: Lanes): Array<string> | void {
132+
if (enableSchedulingProfiler) {
133+
const labels = [];
134+
if (lanes & SyncLane) {
135+
labels.push('Sync');
136+
}
137+
if (lanes & SyncBatchedLane) {
138+
labels.push('SyncBatched');
139+
}
140+
if (lanes & InputDiscreteHydrationLane) {
141+
labels.push('InputDiscreteHydration');
142+
}
143+
if (lanes & InputDiscreteLane) {
144+
labels.push('InputDiscrete');
145+
}
146+
if (lanes & DefaultHydrationLane) {
147+
labels.push('DefaultHydration');
148+
}
149+
if (lanes & DefaultLane) {
150+
labels.push('Default');
151+
}
152+
if (lanes & TransitionHydrationLane) {
153+
labels.push('TransitionHydration');
154+
}
155+
if (lanes & TransitionLanes) {
156+
labels.push('Transition(s)');
157+
}
158+
if (lanes & RetryLanes) {
159+
labels.push('Retry(s)');
160+
}
161+
if (lanes & SelectiveHydrationLane) {
162+
labels.push('SelectiveHydration');
163+
}
164+
if (lanes & IdleHydrationLane) {
165+
labels.push('IdleHydration');
166+
}
167+
if (lanes & IdleLane) {
168+
labels.push('Idle');
169+
}
170+
if (lanes & OffscreenLane) {
171+
labels.push('Offscreen');
172+
}
173+
return labels;
174+
}
175+
}
176+
130177
export const NoTimestamp = -1;
131178

132179
let currentUpdateLanePriority: LanePriority = NoLanePriority;

packages/react-reconciler/src/ReactFiberLane.old.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import invariant from 'shared/invariant';
3939
import {
4040
enableCache,
4141
enableNonInterruptingNormalPri,
42+
enableSchedulingProfiler,
4243
} from 'shared/ReactFeatureFlags';
4344

4445
import {
@@ -127,6 +128,52 @@ const IdleLane: Lanes = /* */ 0b0100000000000000000
127128

128129
export const OffscreenLane: Lane = /* */ 0b1000000000000000000000000000000;
129130

131+
export function getLabelsForLanes(lanes: Lanes): Array<string> | void {
132+
if (enableSchedulingProfiler) {
133+
const labels = [];
134+
if (lanes & SyncLane) {
135+
labels.push('Sync');
136+
}
137+
if (lanes & SyncBatchedLane) {
138+
labels.push('SyncBatched');
139+
}
140+
if (lanes & InputDiscreteHydrationLane) {
141+
labels.push('InputDiscreteHydration');
142+
}
143+
if (lanes & InputDiscreteLane) {
144+
labels.push('InputDiscrete');
145+
}
146+
if (lanes & DefaultHydrationLane) {
147+
labels.push('DefaultHydration');
148+
}
149+
if (lanes & DefaultLane) {
150+
labels.push('Default');
151+
}
152+
if (lanes & TransitionHydrationLane) {
153+
labels.push('TransitionHydration');
154+
}
155+
if (lanes & TransitionLanes) {
156+
labels.push('Transition(s)');
157+
}
158+
if (lanes & RetryLanes) {
159+
labels.push('Retry(s)');
160+
}
161+
if (lanes & SelectiveHydrationLane) {
162+
labels.push('SelectiveHydration');
163+
}
164+
if (lanes & IdleHydrationLane) {
165+
labels.push('IdleHydration');
166+
}
167+
if (lanes & IdleLane) {
168+
labels.push('Idle');
169+
}
170+
if (lanes & OffscreenLane) {
171+
labels.push('Offscreen');
172+
}
173+
return labels;
174+
}
175+
}
176+
130177
export const NoTimestamp = -1;
131178

132179
let currentUpdateLanePriority: LanePriority = NoLanePriority;

packages/react-reconciler/src/SchedulingProfiler.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,20 @@ import type {Lane, Lanes} from './ReactFiberLane.old';
1111
import type {Fiber} from './ReactInternalTypes';
1212
import type {Wakeable} from 'shared/ReactTypes';
1313

14-
import {enableSchedulingProfiler} from 'shared/ReactFeatureFlags';
14+
import {
15+
enableNewReconciler,
16+
enableSchedulingProfiler,
17+
} from 'shared/ReactFeatureFlags';
1518
import ReactVersion from 'shared/ReactVersion';
1619
import getComponentName from 'shared/getComponentName';
1720

21+
import {getLabelsForLanes as getLabelsForLanes_old} from 'react-reconciler/src/ReactFiberLane.old';
22+
import {getLabelsForLanes as getLabelsForLanes_new} from 'react-reconciler/src/ReactFiberLane.new';
23+
24+
const getLabelsForLanes = enableNewReconciler
25+
? getLabelsForLanes_new
26+
: getLabelsForLanes_old;
27+
1828
/**
1929
* If performance exists and supports the subset of the User Timing API that we
2030
* require.
@@ -49,8 +59,14 @@ if (enableSchedulingProfiler) {
4959
}
5060
}
5161

52-
function formatLanes(laneOrLanes: Lane | Lanes): string {
53-
return ((laneOrLanes: any): number).toString();
62+
export function formatLanes(laneOrLanes: Lane | Lanes): string {
63+
let labels = getLabelsForLanes(laneOrLanes);
64+
if (labels != null) {
65+
labels = labels.sort().join(',');
66+
} else {
67+
labels = '';
68+
}
69+
return `${laneOrLanes}-${labels}`;
5470
}
5571

5672
function markAndClear(name) {

0 commit comments

Comments
 (0)