mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-19 20:37:00 -05:00
Optimize module resolution cache for watch and editor (#37055)
* Refactor resolveName * Have resolutions of failed lookups as array and resolved to fileName map
This commit is contained in:
@@ -33,15 +33,13 @@ namespace ts.tscWatch {
|
||||
|
||||
export type Watch = WatchOfConfigFile<EmitAndSemanticDiagnosticsBuilderProgram> | WatchOfFilesAndCompilerOptions<EmitAndSemanticDiagnosticsBuilderProgram>;
|
||||
|
||||
export function createWatchOfConfigFile(configFileName: string, host: WatchedSystem, optionsToExtend?: CompilerOptions, watchOptionsToExtend?: WatchOptions, maxNumberOfFilesToIterateForInvalidation?: number) {
|
||||
export function createWatchOfConfigFile(configFileName: string, host: WatchedSystem, optionsToExtend?: CompilerOptions, watchOptionsToExtend?: WatchOptions) {
|
||||
const compilerHost = createWatchCompilerHostOfConfigFile(configFileName, optionsToExtend || {}, watchOptionsToExtend, host);
|
||||
compilerHost.maxNumberOfFilesToIterateForInvalidation = maxNumberOfFilesToIterateForInvalidation;
|
||||
return createWatchProgram(compilerHost);
|
||||
}
|
||||
|
||||
export function createWatchOfFilesAndCompilerOptions(rootFiles: string[], host: WatchedSystem, options: CompilerOptions = {}, watchOptions?: WatchOptions, maxNumberOfFilesToIterateForInvalidation?: number) {
|
||||
export function createWatchOfFilesAndCompilerOptions(rootFiles: string[], host: WatchedSystem, options: CompilerOptions = {}, watchOptions?: WatchOptions) {
|
||||
const compilerHost = createWatchCompilerHostOfFilesAndCompilerOptions(rootFiles, options, watchOptions, host);
|
||||
compilerHost.maxNumberOfFilesToIterateForInvalidation = maxNumberOfFilesToIterateForInvalidation;
|
||||
return createWatchProgram(compilerHost);
|
||||
}
|
||||
|
||||
@@ -288,7 +286,6 @@ namespace ts.tscWatch {
|
||||
}
|
||||
export interface TscWatchCompile extends TscWatchCompileBase {
|
||||
sys: () => WatchedSystem;
|
||||
maxNumberOfFilesToIterateForInvalidation?: number;
|
||||
}
|
||||
|
||||
export type SystemSnap = ReturnType<WatchedSystem["snap"]>;
|
||||
@@ -308,7 +305,6 @@ namespace ts.tscWatch {
|
||||
sys,
|
||||
cb,
|
||||
commandLineArgs,
|
||||
input.maxNumberOfFilesToIterateForInvalidation
|
||||
);
|
||||
runWatchBaseline({
|
||||
scenario,
|
||||
|
||||
@@ -984,7 +984,6 @@ declare const eval: any`
|
||||
scenario,
|
||||
subScenario: `should not trigger recompilation because of program emit/${subScenario}`,
|
||||
commandLineArgs: ["-w", "-p", `${projectRoot}/tsconfig.json`],
|
||||
maxNumberOfFilesToIterateForInvalidation: 1,
|
||||
sys: () => {
|
||||
const file1: File = {
|
||||
path: `${projectRoot}/file1.ts`,
|
||||
|
||||
@@ -320,7 +320,6 @@ declare module "fs" {
|
||||
scenario,
|
||||
subScenario: `ignores changes in node_modules that start with dot/${subScenario}`,
|
||||
commandLineArgs,
|
||||
maxNumberOfFilesToIterateForInvalidation: 1,
|
||||
sys: () => {
|
||||
const file1: File = {
|
||||
path: `${projectRoot}/test.ts`,
|
||||
|
||||
@@ -418,7 +418,7 @@ namespace ts.projectSystem {
|
||||
});
|
||||
|
||||
describe("resolution when resolution cache size", () => {
|
||||
function verifyWithMaxCacheLimit(limitHit: boolean, useSlashRootAsSomeNotRootFolderInUserDirectory: boolean) {
|
||||
function verifyWithMaxCacheLimit(useSlashRootAsSomeNotRootFolderInUserDirectory: boolean) {
|
||||
const rootFolder = useSlashRootAsSomeNotRootFolderInUserDirectory ? "/user/username/rootfolder/otherfolder/" : "/";
|
||||
const file1: File = {
|
||||
path: rootFolder + "a/b/project/file1.ts",
|
||||
@@ -451,9 +451,6 @@ namespace ts.projectSystem {
|
||||
checkNumberOfProjects(projectService, { configuredProjects: 1 });
|
||||
const project = projectService.configuredProjects.get(configFile.path)!;
|
||||
verifyProject();
|
||||
if (limitHit) {
|
||||
(project as ResolutionCacheHost).maxNumberOfFilesToIterateForInvalidation = 1;
|
||||
}
|
||||
|
||||
file3.content += "export class d {}";
|
||||
host.reloadFS(projectFiles);
|
||||
@@ -495,20 +492,12 @@ namespace ts.projectSystem {
|
||||
}
|
||||
}
|
||||
|
||||
it("limit not hit and project is not at root level", () => {
|
||||
verifyWithMaxCacheLimit(/*limitHit*/ false, /*useSlashRootAsSomeNotRootFolderInUserDirectory*/ true);
|
||||
it("project is not at root level", () => {
|
||||
verifyWithMaxCacheLimit(/*useSlashRootAsSomeNotRootFolderInUserDirectory*/ true);
|
||||
});
|
||||
|
||||
it("limit hit and project is not at root level", () => {
|
||||
verifyWithMaxCacheLimit(/*limitHit*/ true, /*useSlashRootAsSomeNotRootFolderInUserDirectory*/ true);
|
||||
});
|
||||
|
||||
it("limit not hit and project is at root level", () => {
|
||||
verifyWithMaxCacheLimit(/*limitHit*/ false, /*useSlashRootAsSomeNotRootFolderInUserDirectory*/ false);
|
||||
});
|
||||
|
||||
it("limit hit and project is at root level", () => {
|
||||
verifyWithMaxCacheLimit(/*limitHit*/ true, /*useSlashRootAsSomeNotRootFolderInUserDirectory*/ false);
|
||||
it("project is at root level", () => {
|
||||
verifyWithMaxCacheLimit(/*useSlashRootAsSomeNotRootFolderInUserDirectory*/ false);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -902,7 +902,6 @@ export const x = 10;`
|
||||
checkNumberOfProjects(service, { inferredProjects: 1 });
|
||||
const project = service.inferredProjects[0];
|
||||
checkProjectActualFiles(project, files.map(f => f.path));
|
||||
(project as ResolutionCacheHost).maxNumberOfFilesToIterateForInvalidation = 1;
|
||||
host.checkTimeoutQueueLength(0);
|
||||
|
||||
host.ensureFileOrFolder(npmCacheFile);
|
||||
@@ -943,8 +942,6 @@ export const x = 10;`
|
||||
const resolutionTrace = createHostModuleResolutionTrace(host);
|
||||
const service = createProjectService(host);
|
||||
service.openClientFile(file1.path);
|
||||
const project = service.configuredProjects.get(configFile.path)!;
|
||||
(project as ResolutionCacheHost).maxNumberOfFilesToIterateForInvalidation = 1;
|
||||
const expectedTrace = getExpectedNonRelativeModuleResolutionTrace(host, file1, module1, module1Name);
|
||||
getExpectedNonRelativeModuleResolutionTrace(host, file1, module2, module2Name, expectedTrace);
|
||||
verifyTrace(resolutionTrace, expectedTrace);
|
||||
|
||||
Reference in New Issue
Block a user