Skip to content

Commit b01722d

Browse files
authored
Format event with "warning" yellow and prefix with "Event: " (#31536)
It's useful to quickly see where new events are kicking off new rendering. This uses the new "warning" color (yellow) to do that. This is to help distinguish it from the purple (secondary color) which is used for the commit phase which is more of a follow up and it's often that you have several rerenders within one event which makes it hard to tell a part where it starts and event otherwise. For the span marking between previous render within the same event and the next setState, I use secondary-light (light purple) since it's kind of still part of the same sequence at that point. It's usually a spawned render (e.g. setState in useEffect or microtask) but it can also be sequential flushSync. I was bothered by that the event name is the only thing that's lower case so I prefixed it with `Event: ` like the JS traces are. <img width="1499" alt="Screenshot 2024-11-13 at 7 15 45 PM" src="https://github.com/user-attachments/assets/0c81c810-6b5d-4fc7-9bc0-d15b53844ade"> It might be a little confusing why our track starts earlier than the JS one below in the "Main Thread" flamegraph which looks the same. That's because ours is the start of the event time which is when the click happens where as the Main Thread one is when the JS event loop gets around to processing the event.
1 parent c13986d commit b01722d

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Diff for: packages/react-reconciler/src/ReactFiberPerformanceTrack.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,15 @@ export function logBlockingStart(
125125
reusableLaneDevToolDetails.track = 'Blocking';
126126
if (eventTime > 0 && eventType !== null) {
127127
// Log the time from the event timeStamp until we called setState.
128-
reusableLaneDevToolDetails.color = 'secondary-dark';
128+
reusableLaneDevToolDetails.color = eventIsRepeat
129+
? 'secondary-light'
130+
: 'warning';
129131
reusableLaneOptions.start = eventTime;
130132
reusableLaneOptions.end = updateTime > 0 ? updateTime : renderStartTime;
131-
performance.measure(eventIsRepeat ? '' : eventType, reusableLaneOptions);
133+
performance.measure(
134+
eventIsRepeat ? '' : 'Event: ' + eventType,
135+
reusableLaneOptions,
136+
);
132137
}
133138
if (updateTime > 0) {
134139
// Log the time from when we called setState until we started rendering.
@@ -152,15 +157,20 @@ export function logTransitionStart(
152157
reusableLaneDevToolDetails.track = 'Transition';
153158
if (eventTime > 0 && eventType !== null) {
154159
// Log the time from the event timeStamp until we started a transition.
155-
reusableLaneDevToolDetails.color = 'secondary-dark';
160+
reusableLaneDevToolDetails.color = eventIsRepeat
161+
? 'secondary-light'
162+
: 'warning';
156163
reusableLaneOptions.start = eventTime;
157164
reusableLaneOptions.end =
158165
startTime > 0
159166
? startTime
160167
: updateTime > 0
161168
? updateTime
162169
: renderStartTime;
163-
performance.measure(eventIsRepeat ? '' : eventType, reusableLaneOptions);
170+
performance.measure(
171+
eventIsRepeat ? '' : 'Event: ' + eventType,
172+
reusableLaneOptions,
173+
);
164174
}
165175
if (startTime > 0) {
166176
// Log the time from when we started an async transition until we called setState or started rendering.

0 commit comments

Comments
 (0)