microsoft / microsoft/TypeScript

Performance degrades the more wildcards that are contained in TSConfig include or exclude patterns

Offen
#61,103 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Domain: Performance Experimentation Needed Possible Improvement
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

🔎 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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne in src/compiler/utilities.ts bei den Zeilen 9556-9566 und führe dann das verknüpfte typescript_slow_wildcards_repro-Projekt mit den wiederholten tsconfig exclude patterns aus. Vergleiche die Laufzeit des Compilers für große und kleine Mustermengen und berücksichtige beim Überprüfen der erwarteten Leistungsverbesserung das bestehende PR 61104.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers, performance
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.