Skip to content

Commit

Permalink
Add constructor functions for {Symbol,Node}Links
Browse files Browse the repository at this point in the history
Using a constructor function like this can help node better optimize
object allocation. This improves memory usage when compiling
`src/compiler` from **277M** to **270M**, a nice ~3% win.
  • Loading branch information
Swatinem committed Feb 18, 2020
1 parent 7cc4a8d commit ca20613
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1252,15 +1252,22 @@ namespace ts {
}
}

function SymbolLink(this: SymbolLinks) {
}

function getSymbolLinks(symbol: Symbol): SymbolLinks {
if (symbol.flags & SymbolFlags.Transient) return <TransientSymbol>symbol;
const id = getSymbolId(symbol);
return symbolLinks[id] || (symbolLinks[id] = {});
return symbolLinks[id] || (symbolLinks[id] = new (<any>SymbolLink)());
}

function NodeLink(this: NodeLinks) {
this.flags = 0;
}

function getNodeLinks(node: Node): NodeLinks {
const nodeId = getNodeId(node);
return nodeLinks[nodeId] || (nodeLinks[nodeId] = { flags: 0 } as NodeLinks);
return nodeLinks[nodeId] || (nodeLinks[nodeId] = new (<any>NodeLink)());
}

function isGlobalSourceFile(node: Node) {
Expand Down

0 comments on commit ca20613

Please sign in to comment.