microsoft / microsoft/TypeScript
Performance degrades the more wildcards that are contained in TSConfig include or exclude patterns
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 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.
{
"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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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