microsoft / microsoft/TypeScript

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

Abierto
#61,103 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Domain: Performance Experimentation Needed Possible Improvement
Lenguaje dominante
Go
Estrellas
111k
Forks
14.3k
Merge medio
2 d 4 h
PR fusionados (30 d)
132

Descripción

🔎 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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza en src/compiler/utilities.ts, en las líneas 9556-9566, y luego ejecuta el proyecto vinculado typescript_slow_wildcards_repro con los patrones exclude repetidos de tsconfig. Compara el tiempo de ejecución del compilador para conjuntos de patrones grandes y pequeños, y considera el PR 61104 existente al verificar la mejora de rendimiento esperada.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
typescript
Área
compilers, performance
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.