Skip to content

Performance regression in errorOnImplicitAnyModule #26248

@dtinth

Description

@dtinth

TypeScript Version: 3.0.1

Search Terms:
typesPackageExists
Performance slow
tsserver
vscode typescript slow

Description
Since TypeScript 3.0, I find the TypeScript language server is slowing down noticeably. I ran VS Code with TSS_DEBUG=8283 code . to profile where the performance bottleneck is.

image

Most of the time is spent in findReferences function (and its descendant). I am using “Reference CodeLens” which I believe to have caused this command to be executed often.

Looking at the “heavy” graph, tsserver spends most of its time in the typesPackageExists function.

image

Looking at the performance chart, findReferences called typesPackageExists multiple times.

image

The function typesPackageExists appeared in commit 2b9166b:

https://github.com/Microsoft/TypeScript/blob/937afab4b026c9ed527c8369275c749fc8f2af99/src/compiler/checker.ts#L2261-L2264

        function typesPackageExists(packageName: string): boolean {
            return host.getSourceFiles().some(sf => !!sf.resolvedModules && !!forEachEntry(sf.resolvedModules, r =>
                r && r.packageId && r.packageId.name === getTypesPackageName(packageName)));
        }

I set up a breakpoint here:

image

This allows me to see how many source files I have:

image

Therefore, tsserver in VS Code slows down when both conditions are met:

  • References CodeLens is enabled. (Confirmed: Disabling javascript.referencesCodeLens.enabled and typescript.referencesCodeLens.enabled fixed this issue.)
  • The project is large.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions