Skip to content

Commit 4359b77

Browse files
and-oliDevtools-frontend LUCI CQ
authored andcommitted
[RPP] Simplify source map resolver cache
We don't need to cache by process and thread id since the key created based on a call frame contains the data to identify a code location (URL, line, column, etc.) Bug: none Change-Id: Ia11bca73ce510b9bd48ef1a22985ee4793ddb08d Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6080383 Commit-Queue: Andres Olivares <[email protected]> Reviewed-by: Jack Franklin <[email protected]> Commit-Queue: Jack Franklin <[email protected]> Auto-Submit: Andres Olivares <[email protected]>
1 parent bdf44d3 commit 4359b77

File tree

2 files changed

+15
-22
lines changed

2 files changed

+15
-22
lines changed

front_end/panels/timeline/TimelineUIUtils.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,9 +1225,8 @@ describeWithMockConnection('TimelineUIUtils', function() {
12251225
}
12261226

12271227
// Fake that we resolved the entry's name from a sourcemap.
1228-
Timeline.Utils.SourceMapsResolver.SourceMapsResolver.storeResolvedNodeDataForEntry(
1229-
profileEntry.pid, profileEntry.tid, profileEntry.callFrame,
1230-
{name: 'resolved-function-test', devtoolsLocation: null, script: null});
1228+
Timeline.Utils.SourceMapsResolver.SourceMapsResolver.storeResolvedCodeDataForCallFrame(
1229+
profileEntry.callFrame, {name: 'resolved-function-test', devtoolsLocation: null, script: null});
12311230

12321231
const title = Timeline.TimelineUIUtils.TimelineUIUtils.eventTitle(profileEntry);
12331232
assert.strictEqual(title, 'resolved-function-test');

front_end/panels/timeline/utils/SourceMapsResolver.ts

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,8 @@ export class SourceMappingsUpdated extends Event {
2626
}
2727
}
2828

29-
// Resolved code location data is keyed based on
30-
// ProcessID=>ThreadID=> Call frame key.
3129
// The code location key is created as a concatenation of its fields.
32-
export const resolvedCodeLocationDataNames:
33-
Map<Trace.Types.Events.ProcessID, Map<Trace.Types.Events.ThreadID, Map<string, ResolvedCodeLocationData|null>>> =
34-
new Map();
30+
export const resolvedCodeLocationDataNames: Map<string, ResolvedCodeLocationData|null> = new Map();
3531

3632
export class SourceMapsResolver extends EventTarget {
3733
#parsedTrace: Trace.Handlers.Types.ParsedTrace;
@@ -71,6 +67,11 @@ export class SourceMapsResolver extends EventTarget {
7167
*
7268
* TODO(andoli): This can return incorrect scripts if the target page has been reloaded since the trace.
7369
*/
70+
static resolvedCodeLocationForCallFrame(callFrame: Protocol.Runtime.CallFrame): ResolvedCodeLocationData|null {
71+
const codeLocationKey = this.keyForCodeLocation(callFrame as Protocol.Runtime.CallFrame);
72+
return resolvedCodeLocationDataNames.get(codeLocationKey) ?? null;
73+
}
74+
7475
static resolvedCodeLocationForEntry(entry: Trace.Types.Events.Event): ResolvedCodeLocationData|null {
7576
let callFrame = null;
7677
if (Trace.Types.Events.isProfileCall(entry)) {
@@ -82,8 +83,7 @@ export class SourceMapsResolver extends EventTarget {
8283
}
8384
callFrame = stackTrace[0];
8485
}
85-
const codeLocationKey = this.keyForCodeLocation(callFrame as Protocol.Runtime.CallFrame);
86-
return resolvedCodeLocationDataNames.get(entry.pid)?.get(entry.tid)?.get(codeLocationKey) ?? null;
86+
return SourceMapsResolver.resolvedCodeLocationForCallFrame(callFrame as Protocol.Runtime.CallFrame);
8787
}
8888

8989
static resolvedURLForEntry(parsedTrace: Trace.Handlers.Types.ParsedTrace, entry: Trace.Types.Events.Event):
@@ -102,16 +102,10 @@ export class SourceMapsResolver extends EventTarget {
102102
return null;
103103
}
104104

105-
static storeResolvedNodeDataForEntry(
106-
pid: Trace.Types.Events.ProcessID, tid: Trace.Types.Events.ThreadID, callFrame: Protocol.Runtime.CallFrame,
107-
resolvedCodeLocationData: ResolvedCodeLocationData): void {
108-
const resolvedForPid = resolvedCodeLocationDataNames.get(pid) ||
109-
new Map<Trace.Types.Events.ThreadID, Map<string, ResolvedCodeLocationData|null>>();
110-
const resolvedForTid = resolvedForPid.get(tid) || new Map<string, ResolvedCodeLocationData|null>();
105+
static storeResolvedCodeDataForCallFrame(
106+
callFrame: Protocol.Runtime.CallFrame, resolvedCodeLocationData: ResolvedCodeLocationData): void {
111107
const keyForCallFrame = this.keyForCodeLocation(callFrame);
112-
resolvedForTid.set(keyForCallFrame, resolvedCodeLocationData);
113-
resolvedForPid.set(tid, resolvedForTid);
114-
resolvedCodeLocationDataNames.set(pid, resolvedForPid);
108+
resolvedCodeLocationDataNames.set(keyForCallFrame, resolvedCodeLocationData);
115109
}
116110

117111
async install(): Promise<void> {
@@ -167,7 +161,7 @@ export class SourceMapsResolver extends EventTarget {
167161
// is attach. If not, we do not notify the flamechart that mappings
168162
// were updated, since that would trigger a rerender.
169163
let updatedMappings = false;
170-
for (const [pid, threadsInProcess] of this.#parsedTrace.Samples.profilesInProcess) {
164+
for (const [, threadsInProcess] of this.#parsedTrace.Samples.profilesInProcess) {
171165
for (const [tid, threadProfile] of threadsInProcess) {
172166
const nodes = threadProfile.parsedProfile.nodes() ?? [];
173167
const target = this.#targetForThread(tid);
@@ -190,8 +184,8 @@ export class SourceMapsResolver extends EventTarget {
190184
location);
191185
updatedMappings ||= Boolean(uiLocation);
192186

193-
SourceMapsResolver.storeResolvedNodeDataForEntry(
194-
pid, tid, node.callFrame, {name: resolvedFunctionName, devtoolsLocation: uiLocation, script});
187+
SourceMapsResolver.storeResolvedCodeDataForCallFrame(
188+
node.callFrame, {name: resolvedFunctionName, devtoolsLocation: uiLocation, script});
195189
}
196190
}
197191
}

0 commit comments

Comments
 (0)