From 5937ffdf25830739b8e0eae6095fca3bdc132605 Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Wed, 11 Mar 2020 16:40:51 +0100 Subject: [PATCH] Add constructor functions for {Symbol,Node}Links (#36845) 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. --- src/compiler/checker.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f4ec3e8bf66..c32801ac5f5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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; @@ -1271,12 +1278,12 @@ namespace ts { function getSymbolLinks(symbol: Symbol): SymbolLinks { if (symbol.flags & SymbolFlags.Transient) return symbol; const id = getSymbolId(symbol); - return symbolLinks[id] || (symbolLinks[id] = {}); + return symbolLinks[id] || (symbolLinks[id] = new (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 (NodeLinks)()); } function isGlobalSourceFile(node: Node) {