From f1298287d60878ac10f12aac3577bd58b6e9993b Mon Sep 17 00:00:00 2001 From: Chris Tate Date: Mon, 26 Oct 2026 07:58:58 -0500 Subject: [PATCH] Resolve each shipped declaration path once isFallbackDtsPath runs for every type lowering maps (isStdlibFile), and since the fallback declarations moved into per-module files (#2256) it asked declarationPath for the fallback module directory each time. Without an installed declaration root, each answer resolved @scriptc/compiler/scriptc-node-fallback.d.ts through Node's module resolver. Lowering three.js's buffers-animation fixture went from 6.3 s to 43 s. declarationPath now keeps its answers by name until the declaration root changes. --- packages/compiler/src/frontend/dts-paths.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/compiler/src/frontend/dts-paths.ts b/packages/compiler/src/frontend/dts-paths.ts index 638e58641..7e53a2a9b 100644 --- a/packages/compiler/src/frontend/dts-paths.ts +++ b/packages/compiler/src/frontend/dts-paths.ts @@ -7,13 +7,27 @@ export { tsgoPath } from "./ts7/session-path.js"; const require = createRequire(import.meta.url); let installedDeclarationRoot: string | null = null; +/** The paths `declarationPath` answered, by name, for the current root. + * Lowering asks for them once per mapped type (isFallbackDtsPath), and each + * answer without an installed root costs a package resolution. */ +const declarationPaths = new Map(); /** A native distribution supplies its relocatable declaration directory. */ export function setDeclarationRoot(root: string): void { installedDeclarationRoot = root; + declarationPaths.clear(); } function declarationPath(name: string): string { + let path = declarationPaths.get(name); + if (path === undefined) { + path = resolveDeclarationPath(name); + declarationPaths.set(name, path); + } + return path; +} + +function resolveDeclarationPath(name: string): string { return tsgoPath( installedDeclarationRoot === null ? name === "scriptc.d.ts"