Skip to content

Commit

Permalink
Small optimization to avoid serializing runtime source unnecessarily
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Brian Vaughn committed Aug 28, 2021
1 parent 3173c4c commit dfd3b2e
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,13 @@ function extractAndLoadSourceMapJSON(
if (sourceMapIncludesSource(sourceMapJSON, runtimeSourceURL)) {
hookSourceAndMetadata.sourceMapJSON = sourceMapJSON;

// OPTIMIZATION If we've located a source map for this source,
// we'll use it to retrieve the original source (to extract hook names).
// 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.
hookSourceAndMetadata.runtimeSourceCode = null;

break;
}
} else {
Expand Down Expand Up @@ -272,7 +279,16 @@ function extractAndLoadSourceMapJSON(

setterPromises.push(
fetchPromise.then(sourceMapJSON => {
hookSourceAndMetadata.sourceMapJSON = sourceMapJSON;
if (sourceMapJSON !== null) {
hookSourceAndMetadata.sourceMapJSON = sourceMapJSON;

// OPTIMIZATION If we've located a source map for this source,
// we'll use it to retrieve the original source (to extract hook names).
// 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.
hookSourceAndMetadata.runtimeSourceCode = null;
}
}),
);
});
Expand Down

0 comments on commit dfd3b2e

Please sign in to comment.