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 28, 2020
1 parent 7cc4a8d commit 434043e
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 @@ -242,6 +242,13 @@ namespace ts {
ExportNamespace = 1 << 2,
}

function SymbolLinks(this: SymbolLinks) {
}

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

export function getNodeId(node: Node): number {
if (!node.id) {
node.id = nextNodeId;
Expand Down Expand Up @@ -1255,12 +1262,12 @@ namespace ts {
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>SymbolLinks)());
}

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>NodeLinks)());
}

function isGlobalSourceFile(node: Node) {
Expand Down

0 comments on commit 434043e

Please sign in to comment.