microsoft / microsoft/TypeScript

Performance of getSemanticDiagnostics in compiler API

未关闭
#5,192 2 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Domain: API Help Wanted Suggestion
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
132

描述

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.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先阅读 TypeScript compiler API 中 getSemanticDiagnostics(file) 和 program.getSemanticDiagnostics() 的实现,包括 issue 中引用的源代码。确定增量构建如何识别依赖于已更改文件的文件,然后评估一种 API 或缓存方案,避免检查项目中的每个文件,同时仍报告所有受影响的诊断信息。

由索引模型根据 Issue 内容生成。

评估

技术栈
typescript
领域
api, compilers, performance
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。