Skip to content

Commit 29b489f

Browse files
jackfranklinDevtools-frontend LUCI CQ
authored andcommitted
RPP: small performance wins in SamplesHandler
These don't move the needle a considerable amount, but they will save some effort: 1. The `nodes` array that we created is removed. We create it, populate it, and then push each item onto `cdpProfile.nodes`. We can instead create the node + push it on in the same loop, rather than having two loops. 2. Use `for(const key in traceIds)` rather than `Object.entries` to avoid the extra work that gets done. [email protected] Bug: 436491188 Change-Id: I54daf25c504079af61836e5c641287b55b786470 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6827922 Reviewed-by: Alina Varkki <[email protected]> Auto-Submit: Jack Franklin <[email protected]> Commit-Queue: Alina Varkki <[email protected]>
1 parent 947f3e9 commit 29b489f

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

front_end/models/trace/handlers/SamplesHandler.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,9 @@ export function handleEvent(event: Types.Events.Event): void {
146146
if (Types.Events.isProfileChunk(event)) {
147147
const profileData = getOrCreatePreProcessedData(event.pid, event.id);
148148
const cdpProfile = profileData.rawProfile;
149-
const nodesAndSamples: Types.Events.PartialProfile|undefined = event.args?.data?.cpuProfile || {samples: []};
149+
const nodesAndSamples: Types.Events.PartialProfile = event.args?.data?.cpuProfile || {samples: []};
150150
const samples = nodesAndSamples?.samples || [];
151151
const traceIds = event.args?.data?.cpuProfile?.trace_ids;
152-
const nodes: CPUProfile.CPUProfileDataModel.ExtendedProfileNode[] = [];
153152
for (const n of nodesAndSamples?.nodes || []) {
154153
const lineNumber = typeof n.callFrame.lineNumber === 'undefined' ? -1 : n.callFrame.lineNumber;
155154
const columnNumber = typeof n.callFrame.columnNumber === 'undefined' ? -1 : n.callFrame.columnNumber;
@@ -166,22 +165,22 @@ export function handleEvent(event: Types.Events.Event): void {
166165
scriptId,
167166
},
168167
};
169-
nodes.push(node);
168+
cdpProfile.nodes.push(node);
170169
}
171170

172171
const timeDeltas = event.args.data?.timeDeltas || [];
173172
const lines = event.args.data?.lines || Array(samples.length).fill(0);
174-
cdpProfile.nodes.push(...nodes);
175173
cdpProfile.samples?.push(...samples);
176174
cdpProfile.timeDeltas?.push(...timeDeltas);
177175
cdpProfile.lines?.push(...lines);
178176

179177
if (traceIds) {
180-
cdpProfile.traceIds = cdpProfile.traceIds || {};
181-
for (const [key, value] of Object.entries(traceIds)) {
182-
cdpProfile.traceIds[key] = value;
178+
cdpProfile.traceIds ??= {};
179+
for (const key in traceIds) {
180+
cdpProfile.traceIds[key] = traceIds[key];
183181
}
184182
}
183+
185184
if (cdpProfile.samples && cdpProfile.timeDeltas && cdpProfile.samples.length !== cdpProfile.timeDeltas.length) {
186185
console.error('Failed to parse CPU profile.');
187186
return;

0 commit comments

Comments
 (0)