microsoft / microsoft/TypeScript

Performance of getSemanticDiagnostics in compiler API

Open
#5,192 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Domain: API Help Wanted Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

The setup is somewhat similar to the one in the compiler API example (https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#incremental-build-support-using-the-language-services)

The problem, as in the example, is that errors are reported only for files that were directly changed. It doesn't cover the case in which the changed file was a dependency of another file, and even though the file depending on it was not changed, it will still have errors, which won't be reported.

To be more specific, the setup I am talking about is ts-loader + webpack.

What happens is that getSemanticDiagnostics(file) has to be called for every file in the project, which ends up increasing the incremental build times considerably. Even program.getSemanticDiagnostics() iterates through all of the source files as it is seen in the typescript source code.

I can only see this problem fixed from the compiler API. It could expose a method which finds all files dependent on a given file. Because in an incremental build only a single file changed, this should be faster than calling getSemanticDiagnostics() for each and every project file.

The alternative would be some sort of caching on getSemanticDiagnostics() itself, but the compiler would probably have to do internally the same work as above to invalidate the cache on file change. This seems to be equivalent to a getSemanticDiagnosticsForFileAndDependents(file)-like function.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the TypeScript compiler API implementation of getSemanticDiagnostics(file) and program.getSemanticDiagnostics(), including the source code referenced in the issue. Determine how incremental builds identify files dependent on a changed file, then assess an API or caching approach that avoids checking every project file while still reporting all affected diagnostics.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, compilers, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.