Skip to content

Commit dfd3b2e

Browse files
author
Brian Vaughn
committed
Small optimization to avoid serializing runtime source unnecessarily
For source that have source maps, the original source is retrieved using the source map. We only fall back to parsing the full source code is when there's no source map. The source is (potentially) very large, so we can avoid the overhead of serializing it unnecessarily to share it with the worker in this case.
1 parent 3173c4c commit dfd3b2e

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

packages/react-devtools-extensions/src/parseHookNames/loadSourceAndMetadata.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ function extractAndLoadSourceMapJSON(
200200
if (sourceMapIncludesSource(sourceMapJSON, runtimeSourceURL)) {
201201
hookSourceAndMetadata.sourceMapJSON = sourceMapJSON;
202202

203+
// OPTIMIZATION If we've located a source map for this source,
204+
// we'll use it to retrieve the original source (to extract hook names).
205+
// We only fall back to parsing the full source code is when there's no source map.
206+
// The source is (potentially) very large,
207+
// So we can avoid the overhead of serializing it unnecessarily.
208+
hookSourceAndMetadata.runtimeSourceCode = null;
209+
203210
break;
204211
}
205212
} else {
@@ -272,7 +279,16 @@ function extractAndLoadSourceMapJSON(
272279

273280
setterPromises.push(
274281
fetchPromise.then(sourceMapJSON => {
275-
hookSourceAndMetadata.sourceMapJSON = sourceMapJSON;
282+
if (sourceMapJSON !== null) {
283+
hookSourceAndMetadata.sourceMapJSON = sourceMapJSON;
284+
285+
// OPTIMIZATION If we've located a source map for this source,
286+
// we'll use it to retrieve the original source (to extract hook names).
287+
// We only fall back to parsing the full source code is when there's no source map.
288+
// The source is (potentially) very large,
289+
// So we can avoid the overhead of serializing it unnecessarily.
290+
hookSourceAndMetadata.runtimeSourceCode = null;
291+
}
276292
}),
277293
);
278294
});

0 commit comments

Comments
 (0)