Skip to content
This repository has been archived by the owner on Dec 1, 2019. It is now read-only.

Performance slowdown due to case insensitivity #507

Closed
lukasgeiter opened this issue Oct 14, 2017 · 1 comment
Closed

Performance slowdown due to case insensitivity #507

lukasgeiter opened this issue Oct 14, 2017 · 1 comment

Comments

@lukasgeiter
Copy link

I've recently made a small change to my project and now my build is roughly 3x slower.

I have created a second tsconfig.json file and wanted to make use of the extends feature to inherit from my original config file. Apparently this has an influence on how TypeScript resolves the baseUrl in compilerOptions. With a single tsconfig.json a simple . becomes C:/Path/To/Project, when using extends however TypeScript converts it to lowercase c:/path/to/project.
While this inconsistency could be considered an issue on the TypeScript side it's still technically correct since I'm running this on a case insensitive file system.

Now as mentioned in the beginning, after this change my build still works exactly the same it just takes a lot longer. I've pinpointed the cause for this in updateFile() of checker/runtime.ts:332:

const file = files.get(fileName);
if (file) {
    let updated = false;
    if (file.fileName !== fileName) {
        if (caseInsensitive) {
            file.fileName = fileName; // use most recent name for case-sensitive file systems
            updated = true;
        } else {
            // omitted for brevity
        }
    }
    if (file.text !== text) { updated = updated || true; }
    if (!updated) {
        return;
    }
    projectVersion++;
    file.version++;
    file.text = text;
    file.snapshot = compiler.ScriptSnapshot.fromString(text);
}

If the file can be found in the internal case insensitive map but the file names don't exactly match (different case) and it is a case insensitive file system, the file is considered "updated" and the file as well as project version is increased.
This increased project version results in the fast check in TypeScript's synchronizeHostData() to fail many more times that it would have to which causes it to repeatedly do things even though nothing actually changed.

Removing this one line updated = true actually fixes my performance issue. However, I was a bit hesitant to open a PR because I'm not sure if there is a scenario that actually requires the versions to be incremented in that case.

@s-panferov
Copy link
Owner

@lukasgeiter thank you for this investigation, this is very interesting. I think this should be fixed indeed. I'll make some investigation.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants