microsoft / microsoft/TypeScript
Performance degrades the more wildcards that are contained in TSConfig include or exclude patterns
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
### 🔎 Search Terms
wildcard pattern include exclude tsconfig regex regexp regular expression glob performance slow node
### 🕗 Version & Regression Information
- This is the behavior in every version I tried
### ⏯ Playground Link
_No response_
### 💻 Code
Create a TS project with any empty TS file and the following TSConfig.
```json
{
"compilerOptions": {
"noCheck": true,
"noEmit": true,
"noResolve": true,
},
"exclude": [
"alpha/beta/gamma/delta/epsilon/zeta/eta/theta/iota/kappa/lambda/**/*.ts",
"alpha/beta/gamma/delta/epsilon/zeta/eta/theta/iota/kappa/lambda/**/*.ts",
"alpha/beta/gamma/delta/epsilon/zeta/eta/theta/iota/kappa/lambda/**/*.ts",
...repeat a couple hundred or more times
]
}
```
I've created a repo to more easily reproduce the behavior: https://github.com/MichaelMitchell-at/typescript_slow_wildcards_repro
### 🙁 Actual behavior
`tsc` takes several seconds to run on the project, even though there is no work to do and there are no files to compare the `exclude` patterns against. In fact, running `tsc` with `node --jitless` is much faster than without.
### 🙂 Expected behavior
`tsc` should complete quickly.
### Additional information about the issue
I've determined through profiling that the issue is that a giant `RegExp` combining all the patterns gets created which is very slow to evaluate.
https://github.com/microsoft/TypeScript/blob/739d729ecce60771c23723aad932ab35a34df82d/src/compiler/utilities.ts#L9556-L9566
From my testing, it's much faster to build a separate `RegExp` for each pattern and test them one by one for large number of patterns and for a small number of patterns there is no perceivable difference in speed. I've created a PR implementing this change which greatly improves the performance: https://github.com/microsoft/TypeScript/pull/61104
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 src/compiler/utilities.ts 的第 9556-9566 行开始,然后使用重复的 tsconfig exclude 模式运行链接的 typescript_slow_wildcards_repro 项目。比较大规模和小规模模式集的编译器运行时间,并在验证预期的性能改进时考虑现有的 PR 61104。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- compilers, performance
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 25/100