Skip to content

Commit 9e6f101

Browse files
and-oliDevtools-frontend LUCI CQ
authored andcommitted
[RPP] Add manual parsing of JS scheduling events for backwards compat
A partial revert of [1] to ensure async calls are computed in old traces. We'll keep this backwards compatibility behavior for some time and then remove it since traces taken with chrome 133 will include the new events that allow us to generalize the computation of async calls. [1] https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6054289 Bug: 383974422 Change-Id: I6844dfe0d4ffb9d65b23689e09e994e1b81ffb7b Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6091377 Commit-Queue: Andres Olivares <[email protected]> Reviewed-by: Jack Franklin <[email protected]>
1 parent 3036661 commit 9e6f101

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

front_end/models/trace/handlers/InitiatorsHandler.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,26 @@ const eventToInitiatorMap = new Map<Types.Events.Event, Types.Events.Event>();
3030
// multiple events, hence why the value for this map is an array.
3131
const initiatorToEventsMap = new Map<Types.Events.Event, Types.Events.Event[]>();
3232

33+
// Note: we are keeping the parsing of the following async JS schedulers
34+
// for backwards compatibility only. They are targeted to be removed
35+
// completely by M134. See more details at crbug.com/383974422
36+
// TODO(andoli): remove manual parsing of async JS schedulers.
37+
const requestAnimationFrameEventsById: Map<number, Types.Events.RequestAnimationFrame> = new Map();
38+
const timerInstallEventsById: Map<number, Types.Events.TimerInstall> = new Map();
39+
const requestIdleCallbackEventsById: Map<number, Types.Events.RequestIdleCallback> = new Map();
40+
3341
const webSocketCreateEventsById: Map<number, Types.Events.WebSocketCreate> = new Map();
3442
const schedulePostTaskCallbackEventsById: Map<number, Types.Events.SchedulePostTaskCallback> = new Map();
3543

3644
export function reset(): void {
3745
lastScheduleStyleRecalcByFrame.clear();
3846
lastInvalidationEventForFrame.clear();
3947
lastUpdateLayoutTreeByFrame.clear();
48+
timerInstallEventsById.clear();
4049
eventToInitiatorMap.clear();
4150
initiatorToEventsMap.clear();
51+
requestAnimationFrameEventsById.clear();
52+
requestIdleCallbackEventsById.clear();
4253
webSocketCreateEventsById.clear();
4354
schedulePostTaskCallbackEventsById.clear();
4455
}
@@ -117,6 +128,36 @@ export function handleEvent(event: Types.Events.Event): void {
117128
}
118129
// Now clear the last invalidation for the frame: the last invalidation has been linked to a Layout event, so it cannot be the initiator for any future layouts.
119130
lastInvalidationEventForFrame.delete(event.args.beginData.frame);
131+
} else if (Types.Events.isRequestAnimationFrame(event)) {
132+
requestAnimationFrameEventsById.set(event.args.data.id, event);
133+
} else if (Types.Events.isFireAnimationFrame(event)) {
134+
// If we get a fire event, that means we should have had the
135+
// RequestAnimationFrame event by now. If so, we can set that as the
136+
// initiator for the fire event.
137+
const matchingRequestEvent = requestAnimationFrameEventsById.get(event.args.data.id);
138+
if (matchingRequestEvent) {
139+
storeInitiator({
140+
event,
141+
initiator: matchingRequestEvent,
142+
});
143+
}
144+
} else if (Types.Events.isTimerInstall(event)) {
145+
timerInstallEventsById.set(event.args.data.timerId, event);
146+
} else if (Types.Events.isTimerFire(event)) {
147+
const matchingInstall = timerInstallEventsById.get(event.args.data.timerId);
148+
if (matchingInstall) {
149+
storeInitiator({event, initiator: matchingInstall});
150+
}
151+
} else if (Types.Events.isRequestIdleCallback(event)) {
152+
requestIdleCallbackEventsById.set(event.args.data.id, event);
153+
} else if (Types.Events.isFireIdleCallback(event)) {
154+
const matchingRequestEvent = requestIdleCallbackEventsById.get(event.args.data.id);
155+
if (matchingRequestEvent) {
156+
storeInitiator({
157+
event,
158+
initiator: matchingRequestEvent,
159+
});
160+
}
120161
} else if (Types.Events.isWebSocketCreate(event)) {
121162
webSocketCreateEventsById.set(event.args.data.identifier, event);
122163
} else if (Types.Events.isWebSocketInfo(event) || Types.Events.isWebSocketTransfer(event)) {

0 commit comments

Comments
 (0)