@samitouri / QOS-React-1 / commits / b01722d585

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.

Sebastian Markbåge committed Nov 14, 2024 at 16:44 UTC b01722d58533e5e2664a71b70031e1c5390d813b
1 file changed +14 -4
packages/react-reconciler/src/ReactFiberPerformanceTrack.js
+14 -4
@@ -125,10 +125,15 @@ export function logBlockingStart(
125 reusableLaneDevToolDetails.track = 'Blocking';
126 if (eventTime > 0 && eventType !== null) {
127 // 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';
131 reusableLaneOptions.start = eventTime;
132 reusableLaneOptions.end = updateTime > 0 ? updateTime : renderStartTime;
131 - performance.measure(eventIsRepeat ? '' : eventType, reusableLaneOptions);
133 + performance.measure(
134 + eventIsRepeat ? '' : 'Event: ' + eventType,
135 + reusableLaneOptions,
136 + );
137 }
138 if (updateTime > 0) {
139 // Log the time from when we called setState until we started rendering.
@@ -152,7 +157,9 @@ export function logTransitionStart(
157 reusableLaneDevToolDetails.track = 'Transition';
158 if (eventTime > 0 && eventType !== null) {
159 // 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';
163 reusableLaneOptions.start = eventTime;
164 reusableLaneOptions.end =
165 startTime > 0
@@ -160,7 +167,10 @@ export function logTransitionStart(
167 : updateTime > 0
168 ? updateTime
169 : renderStartTime;
163 - performance.measure(eventIsRepeat ? '' : eventType, reusableLaneOptions);
170 + performance.measure(
171 + eventIsRepeat ? '' : 'Event: ' + eventType,
172 + reusableLaneOptions,
173 + );
174 }
175 if (startTime > 0) {
176 // Log the time from when we started an async transition until we called setState or started rendering.