Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DevTools: Hook names optimizations #22403

Merged
merged 3 commits into from
Sep 23, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const runtimeURLToMetadataCache: LRUCache<
);
}

console.log(`runtimeURLToMetadataCache() dispose of "${runtimeSourceURL}"`);
bvaughn marked this conversation as resolved.
Show resolved Hide resolved
const sourceConsumer = metadata.sourceConsumer;
if (sourceConsumer !== null) {
sourceConsumer.destroy();
Expand Down Expand Up @@ -249,25 +250,6 @@ function initializeHookParsedMetadata(
};

locationKeyToHookParsedMetadata.set(locationKey, hookParsedMetadata);

const runtimeSourceURL = hookSourceAndMetadata.runtimeSourceURL;

// If we've already loaded the source map info for this file,
// we can skip reloading it (and more importantly, re-parsing it).
const runtimeMetadata = runtimeURLToMetadataCache.get(runtimeSourceURL);
if (runtimeMetadata != null) {
if (__DEBUG__) {
console.groupCollapsed(
`parseHookNames() Found cached runtime metadata for file "${runtimeSourceURL}"`,
);
console.log(runtimeMetadata);
console.groupEnd();
}
hookParsedMetadata.metadataConsumer = runtimeMetadata.metadataConsumer;
hookParsedMetadata.sourceConsumer = runtimeMetadata.sourceConsumer;
hookParsedMetadata.sourceMapConsumer =
runtimeMetadata.sourceMapConsumer;
}
},
);

Expand Down Expand Up @@ -635,32 +617,40 @@ function parseSourceMaps(
}

const sourceMapJSON = hookSourceAndMetadata.sourceMapJSON;
if (sourceMapJSON != null) {
hookParsedMetadata.metadataConsumer = withSyncPerfMeasurements(
'new SourceMapMetadataConsumer(sourceMapJSON)',
() => new SourceMapMetadataConsumer(sourceMapJSON),
);
hookParsedMetadata.sourceConsumer = withSyncPerfMeasurements(
'new SourceMapConsumer(sourceMapJSON)',
() => new SourceMapConsumer(sourceMapJSON),
);

const runtimeSourceURL = hookSourceAndMetadata.runtimeSourceURL;
if (hookParsedMetadata.sourceConsumer === null) {
bvaughn marked this conversation as resolved.
Show resolved Hide resolved
if (sourceMapJSON != null) {
hookParsedMetadata.sourceConsumer = withSyncPerfMeasurements(
'new SourceMapConsumer(sourceMapJSON)',
() => new SourceMapConsumer(sourceMapJSON),
);
}
}

// Only set once to avoid triggering eviction/cleanup code.
if (!runtimeURLToMetadataCache.has(runtimeSourceURL)) {
if (__DEBUG__) {
console.log(
`parseSourceMaps() Caching runtime metadata for "${runtimeSourceURL}"`,
);
}
if (hookParsedMetadata.metadataConsumer === null) {
if (sourceMapJSON != null) {
hookParsedMetadata.metadataConsumer = withSyncPerfMeasurements(
'new SourceMapMetadataConsumer(sourceMapJSON)',
() => new SourceMapMetadataConsumer(sourceMapJSON),
);
}
}

runtimeURLToMetadataCache.set(runtimeSourceURL, {
metadataConsumer: hookParsedMetadata.metadataConsumer,
sourceConsumer: hookParsedMetadata.sourceConsumer,
sourceMapConsumer: null,
});
const runtimeSourceURL = hookSourceAndMetadata.runtimeSourceURL;

// Only set once to avoid triggering eviction/cleanup code.
if (!runtimeURLToMetadataCache.has(runtimeSourceURL)) {
if (__DEBUG__) {
console.log(
`parseSourceMaps() Caching runtime metadata for "${runtimeSourceURL}"`,
);
}

runtimeURLToMetadataCache.set(runtimeSourceURL, {
metadataConsumer: hookParsedMetadata.metadataConsumer,
sourceConsumer: hookParsedMetadata.sourceConsumer,
sourceMapConsumer: null,
});
}
},
);
Expand All @@ -679,31 +669,43 @@ function parseSourceMapsAlternate(
throw Error(`Expected to find HookParsedMetadata for "${locationKey}"`);
}

const sourceMapJSON = hookSourceAndMetadata.sourceMapJSON;
if (sourceMapJSON != null) {
hookParsedMetadata.metadataConsumer = withSyncPerfMeasurements(
'new SourceMapMetadataConsumer(sourceMapJSON)',
() => new SourceMapMetadataConsumer(sourceMapJSON),
);
hookParsedMetadata.sourceMapConsumer = withSyncPerfMeasurements(
'new SourceMapCodecConsumer(sourceMapJSON)',
() => SourceMapCodecConsumer(sourceMapJSON),
);
const {runtimeSourceURL, sourceMapJSON} = hookSourceAndMetadata;

const runtimeSourceURL = hookSourceAndMetadata.runtimeSourceURL;
// If we've already loaded the source map info for this file,
// we can skip reloading it (and more importantly, re-parsing it).
const runtimeMetadata = runtimeURLToMetadataCache.get(runtimeSourceURL);
if (runtimeMetadata != null) {
bvaughn marked this conversation as resolved.
Show resolved Hide resolved
if (__DEBUG__) {
console.groupCollapsed(
`parseHookNames() Found cached runtime metadata for file "${runtimeSourceURL}"`,
);
console.log(runtimeMetadata);
console.groupEnd();
}

// Only set once to avoid triggering eviction/cleanup code.
if (!runtimeURLToMetadataCache.has(runtimeSourceURL)) {
if (__DEBUG__) {
console.log(
`parseSourceMaps() Caching runtime metadata for "${runtimeSourceURL}"`,
);
}
hookParsedMetadata.metadataConsumer = runtimeMetadata.metadataConsumer;
hookParsedMetadata.sourceConsumer = runtimeMetadata.sourceConsumer;
hookParsedMetadata.sourceMapConsumer = runtimeMetadata.sourceMapConsumer;
} else {
if (sourceMapJSON != null) {
const sourceMapConsumer = withSyncPerfMeasurements(
'new SourceMapCodecConsumer(sourceMapJSON)',
() => SourceMapCodecConsumer(sourceMapJSON),
);

const metadataConsumer = withSyncPerfMeasurements(
'new SourceMapMetadataConsumer(sourceMapJSON)',
() => new SourceMapMetadataConsumer(sourceMapJSON),
);

hookParsedMetadata.metadataConsumer = metadataConsumer;
hookParsedMetadata.sourceMapConsumer = sourceMapConsumer;

// Only set once to avoid triggering eviction/cleanup code.
runtimeURLToMetadataCache.set(runtimeSourceURL, {
metadataConsumer: hookParsedMetadata.metadataConsumer,
metadataConsumer: metadataConsumer,
sourceConsumer: null,
sourceMapConsumer: hookParsedMetadata.sourceMapConsumer,
sourceMapConsumer: sourceMapConsumer,
});
}
}
Expand Down