From dfd3b2e601472f007a6f1f6b32a0e5e7e961be5d Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Sat, 28 Aug 2021 10:36:23 -0700 Subject: [PATCH] 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. --- .../parseHookNames/loadSourceAndMetadata.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/react-devtools-extensions/src/parseHookNames/loadSourceAndMetadata.js b/packages/react-devtools-extensions/src/parseHookNames/loadSourceAndMetadata.js index 0d7c23867854d..eb7ace99e1655 100644 --- a/packages/react-devtools-extensions/src/parseHookNames/loadSourceAndMetadata.js +++ b/packages/react-devtools-extensions/src/parseHookNames/loadSourceAndMetadata.js @@ -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 { @@ -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; + } }), ); });