microsoft / microsoft/TypeScript
Performance issue if many symbols are declared in repeated namespaces
Personne n'a encore pris cette issue.
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.4k
- Merge moyen
- 1 j 19 h
- PR mergées (30 j)
- 117
Description
Bug Report
🔎 Search Terms
addDeclarationToSymbol, pushIfUnique, performance namespace bind
🕗 Version & Regression Information
This is the behavior in every version I tried: v4.9.4, v5.0.2
⏯ Playground Link
Repro in: https://github.com/frigus02/test-ts-add-declaration-to-symbol-set
Playground link with relevant code
💻 Code
We have a .d.ts generator that emits symbols in nested namespaces. For simplicity the generator always emits the entire namespace. Example:
declare namespace __generated.foo.bar {
export class A {}
}
declare namespace __generated.foo.bar {
export class B {}
}
declare namespace __generated.foo.bar.baz {
export class C {}
}
// Repeat that a few thousand times
It seems this pattern runs into a performance issue inside addDeclarationToSymbol. It calls appendIfUnique(symbol.declarations, node), which iterates through the symbol.declarations array. The code above leads to lots of declarations of the symbols __generated, __generated.foo, etc.
The patch tsc_patch.diff uses a Set rather than iterating the array. This seems to speed up the build time significantly.
🙁 Actual behavior / 🙂 Expected behavior
The build is slower than it could be. A real project (which I can't share publicly) takes ~40 seconds to build currently. With the patch is takes ~16 seconds.
The example in https://github.com/frigus02/test-ts-add-declaration-to-symbol-set shows a "Total time" of 5.61s vs 1.19s.
Question
I realize that we could change the code generator to fix this. Unfortunately that is trickier than it seems and we likely can't do that in the next ~year.
Do you think such a patch (using a Set) is feasible here? If yes, I'd be happy to prepare a PR.
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par addDeclarationToSymbol et son appel à appendIfUnique, puis reproduisez le cas d’un namespace répété à l’aide du dépôt de test lié et de l’exemple Playground. Comparez le comportement actuel et le comportement proposé basé sur Set, en vérifiant l’unicité des déclarations et les performances du compilateur ; le travail est terminé lorsque la régression est couverte et que le ralentissement signalé est corrigé sans modifier les déclarations émises.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- typescript
- Domaine
- compilers, performance
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100