Skip to content

Commit 6fbb547

Browse files
szuendDevtools-frontend LUCI CQ
authored andcommitted
[sdk] Use source map cache when loading source maps
This CL wires up the SourceMapCache in the source map manager. Since SourceMapManager works for both Scripts and Stylesheets, we add a new 'debugId' getter to the 'FrameAssociated' interface. Drive-by: Turn 'loadSourceMap' into a bottle-neck. [email protected] Fixed: 442508443 Change-Id: I4e0765241db49b4eebca1b65790ea3552a2b7370 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6903228 Reviewed-by: Philip Pfaffe <[email protected]> Commit-Queue: Simon Zünd <[email protected]>
1 parent d5acc49 commit 6fbb547

File tree

5 files changed

+38
-9
lines changed

5 files changed

+38
-9
lines changed

front_end/core/sdk/CSSStyleSheetHeader.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {DeferredDOMNode} from './DOMModel.js';
1313
import type {FrameAssociated} from './FrameAssociated.js';
1414
import type {PageResourceLoadInitiator} from './PageResourceLoader.js';
1515
import {ResourceTreeModel} from './ResourceTreeModel.js';
16+
import type {DebugId} from './SourceMap.js';
1617

1718
const UIStrings = {
1819
/**
@@ -188,4 +189,8 @@ export class CSSStyleSheetHeader implements TextUtils.ContentProvider.ContentPro
188189
initiatorUrl: this.hasSourceURL ? Platform.DevToolsPath.EmptyUrlString : this.sourceURL,
189190
};
190191
}
192+
193+
debugId(): DebugId|null {
194+
return null;
195+
}
191196
}

front_end/core/sdk/FrameAssociated.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
// found in the LICENSE file.
44

55
import type {PageResourceLoadInitiator} from './PageResourceLoader.js';
6+
import type {DebugId} from './SourceMap.js';
7+
68
export interface FrameAssociated {
7-
createPageResourceLoadInitiator: () => PageResourceLoadInitiator;
9+
createPageResourceLoadInitiator(): PageResourceLoadInitiator;
10+
debugId(): DebugId|null;
811
}

front_end/core/sdk/Script.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import type {FrameAssociated} from './FrameAssociated.js';
4444
import type {PageResourceLoadInitiator} from './PageResourceLoader.js';
4545
import {ResourceTreeModel} from './ResourceTreeModel.js';
4646
import type {ExecutionContext} from './RuntimeModel.js';
47-
import type {SourceMap} from './SourceMap.js';
47+
import type {DebugId, SourceMap} from './SourceMap.js';
4848
import type {Target} from './Target.js';
4949

5050
const UIStrings = {
@@ -425,6 +425,10 @@ export class Script implements TextUtils.ContentProvider.ContentProvider, FrameA
425425
return {target: this.target(), frameId: this.frameId, initiatorUrl: this.embedderName()};
426426
}
427427

428+
debugId(): DebugId|null {
429+
return this.buildId as (DebugId | null);
430+
}
431+
428432
/**
429433
* Translates the `rawLocation` from line and column number in terms of what V8 understands
430434
* to a script relative location. Specifically this means that for inline `<script>`'s

front_end/core/sdk/SourceMapManager.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ describe('SourceMapManager', () => {
110110
createPageResourceLoadInitiator(): SDK.PageResourceLoader.PageResourceLoadInitiator {
111111
return {target: this.target, frameId: null, initiatorUrl: null};
112112
}
113+
114+
debugId(): SDK.SourceMap.DebugId|null {
115+
return null;
116+
}
113117
}
114118

115119
describe('attachSourceMap', () => {

front_end/core/sdk/SourceMapManager.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import * as Platform from '../platform/platform.js';
77

88
import type {FrameAssociated} from './FrameAssociated.js';
99
import {PageResourceLoader, type PageResourceLoadInitiator} from './PageResourceLoader.js';
10-
import {parseSourceMap, SourceMap, type SourceMapV3} from './SourceMap.js';
10+
import {type DebugId, parseSourceMap, SourceMap, type SourceMapV3} from './SourceMap.js';
11+
import {SourceMapCache} from './SourceMapCache.js';
1112
import {type Target, Type} from './Target.js';
1213

1314
export class SourceMapManager<T extends FrameAssociated> extends Common.ObjectWrapper.ObjectWrapper<EventTypes<T>> {
@@ -105,7 +106,7 @@ export class SourceMapManager<T extends FrameAssociated> extends Common.ObjectWr
105106
this.#attachingClient = null;
106107
const initiator = client.createPageResourceLoadInitiator();
107108
clientData.sourceMapPromise =
108-
loadSourceMap(sourceMapURL, initiator)
109+
loadSourceMap(sourceMapURL, client.debugId(), initiator)
109110
.then(
110111
payload => {
111112
const sourceMap = new SourceMap(sourceURL, sourceMapURL, payload);
@@ -169,10 +170,23 @@ export class SourceMapManager<T extends FrameAssociated> extends Common.ObjectWr
169170
}
170171

171172
export async function loadSourceMap(
172-
url: Platform.DevToolsPath.UrlString, initiator: PageResourceLoadInitiator): Promise<SourceMapV3> {
173+
url: Platform.DevToolsPath.UrlString, debugId: DebugId|null,
174+
initiator: PageResourceLoadInitiator): Promise<SourceMapV3> {
173175
try {
176+
if (debugId) {
177+
const cachedSourceMap = await SourceMapCache.instance().get(debugId);
178+
if (cachedSourceMap) {
179+
return cachedSourceMap;
180+
}
181+
}
182+
174183
const {content} = await PageResourceLoader.instance().loadResource(url, initiator);
175-
return parseSourceMap(content);
184+
const sourceMap = parseSourceMap(content);
185+
if ('debugId' in sourceMap && sourceMap.debugId) {
186+
// In case something goes wrong with updating the cache, we still want to use the source map.
187+
await SourceMapCache.instance().set(sourceMap.debugId as DebugId, sourceMap).catch();
188+
}
189+
return sourceMap;
176190
} catch (cause) {
177191
throw new Error(`Could not load content for ${url}: ${cause.message}`, {cause});
178192
}
@@ -181,10 +195,9 @@ export async function loadSourceMap(
181195
export async function tryLoadSourceMap(
182196
url: Platform.DevToolsPath.UrlString, initiator: PageResourceLoadInitiator): Promise<SourceMapV3|null> {
183197
try {
184-
const {content} = await PageResourceLoader.instance().loadResource(url, initiator);
185-
return parseSourceMap(content);
198+
return await loadSourceMap(url, null, initiator);
186199
} catch (cause) {
187-
console.error(`Could not load content for ${url}: ${cause.message}`, {cause});
200+
console.error(cause);
188201
return null;
189202
}
190203
}

0 commit comments

Comments
 (0)