Skip to content

Commit 5937ffd

Browse files
authored
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.
1 parent 20625a9 commit 5937ffd

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/compiler/checker.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,13 @@ namespace ts {
242242
ExportNamespace = 1 << 2,
243243
}
244244

245+
function SymbolLinks(this: SymbolLinks) {
246+
}
247+
248+
function NodeLinks(this: NodeLinks) {
249+
this.flags = 0;
250+
}
251+
245252
export function getNodeId(node: Node): number {
246253
if (!node.id) {
247254
node.id = nextNodeId;
@@ -1271,12 +1278,12 @@ namespace ts {
12711278
function getSymbolLinks(symbol: Symbol): SymbolLinks {
12721279
if (symbol.flags & SymbolFlags.Transient) return <TransientSymbol>symbol;
12731280
const id = getSymbolId(symbol);
1274-
return symbolLinks[id] || (symbolLinks[id] = {});
1281+
return symbolLinks[id] || (symbolLinks[id] = new (<any>SymbolLinks)());
12751282
}
12761283

12771284
function getNodeLinks(node: Node): NodeLinks {
12781285
const nodeId = getNodeId(node);
1279-
return nodeLinks[nodeId] || (nodeLinks[nodeId] = { flags: 0 } as NodeLinks);
1286+
return nodeLinks[nodeId] || (nodeLinks[nodeId] = new (<any>NodeLinks)());
12801287
}
12811288

12821289
function isGlobalSourceFile(node: Node) {

0 commit comments

Comments
 (0)