


























@@ -88,6 +88,8 @@ type BundledChannelLoadContext = {
8888};
89899090const log = createSubsystemLogger("channels");
91+const MAX_BUNDLED_CHANNEL_LOAD_CONTEXTS = 32;
92+const bundledChannelLoadContextsByRoot = new Map<string, BundledChannelLoadContext>();
91939294function resolveChannelPluginModuleEntry(
9395moduleExport: unknown,
@@ -310,9 +312,27 @@ function resolveActiveBundledChannelLoadScope(): {
310312loadContext: BundledChannelLoadContext;
311313} {
312314const rootScope = resolveBundledChannelRootScope();
315+const cachedContext = bundledChannelLoadContextsByRoot.get(rootScope.cacheKey);
316+if (cachedContext) {
317+bundledChannelLoadContextsByRoot.delete(rootScope.cacheKey);
318+bundledChannelLoadContextsByRoot.set(rootScope.cacheKey, cachedContext);
319+return {
320+ rootScope,
321+loadContext: cachedContext,
322+};
323+}
324+const loadContext = createBundledChannelLoadContext();
325+bundledChannelLoadContextsByRoot.set(rootScope.cacheKey, loadContext);
326+while (bundledChannelLoadContextsByRoot.size > MAX_BUNDLED_CHANNEL_LOAD_CONTEXTS) {
327+const oldestKey = bundledChannelLoadContextsByRoot.keys().next().value;
328+if (oldestKey === undefined) {
329+break;
330+}
331+bundledChannelLoadContextsByRoot.delete(oldestKey);
332+}
313333return {
314334 rootScope,
315-loadContext: createBundledChannelLoadContext(),
335+ loadContext,
316336};
317337}
318338此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。