microsoft / microsoft/TypeScript
Performance issue if many symbols are declared in repeated namespaces
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia da addDeclarationToSymbol e dalla sua chiamata a appendIfUnique, quindi riproduci il caso di un namespace ripetuto usando il repository di test collegato e l’esempio Playground. Confronta il comportamento attuale e quello proposto basato su Set, verificando l’unicità delle dichiarazioni e le prestazioni del compilatore; il lavoro è completato quando la regressione è coperta e il rallentamento segnalato è risolto senza modificare le dichiarazioni emesse.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers, performance
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100