docs: clarify alias map memoization rationale

This commit is contained in:
Peter Steinberger
2026-04-20 13:56:18 +01:00
parent 53176153a2
commit 099d4b50b6
2 changed files with 4 additions and 8 deletions

View File

@@ -1058,7 +1058,7 @@ export const syntheticRuntimeMarker = {
});
describe("buildPluginLoaderAliasMap memoization", () => {
it("returns the same object reference for identical inputs (jiti sentinel safety)", () => {
it("returns the same object reference for identical effective context", () => {
const fixture = createPluginSdkAliasFixture();
const sourceRootAlias = path.join(fixture.root, "src", "plugin-sdk", "root-alias.cjs");
fs.writeFileSync(sourceRootAlias, "module.exports = {};\n", "utf-8");
@@ -1070,8 +1070,6 @@ describe("buildPluginLoaderAliasMap memoization", () => {
const first = buildPluginLoaderAliasMap(sourcePluginEntry);
const second = buildPluginLoaderAliasMap(sourcePluginEntry);
// Reference identity is critical: jiti's normalizeAliases uses a
// reference-identity sentinel to skip O(N²) re-processing.
expect(second).toBe(first);
});

View File

@@ -430,11 +430,9 @@ export function resolveExtensionApiAlias(params: LoaderModuleResolveParams = {})
return null;
}
// Memoize alias maps by inputs so the same object reference is returned for
// identical parameters. jiti's `normalizeAliases` uses a reference-identity
// sentinel (`if (e[pt]) return e`) to skip its O(N²) normalization — returning
// the same object lets the sentinel fire on the 2nd+ call instead of repeating
// the full cycle every time. See #68983.
// Memoize alias maps by effective resolution context so repeated loader setup
// avoids rebuilding the same filesystem-derived map. Include cwd/env inputs
// because the fallback root and private QA alias surfaces depend on them.
const aliasMapCache = new Map<string, Record<string, string>>();
function buildPluginLoaderAliasMapCacheKey(params: {