Skip to content

Commit 434043e

Browse files
committed
Add constructor functions for {Symbol,Node}Links
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 7cc4a8d commit 434043e

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;
@@ -1255,12 +1262,12 @@ namespace ts {
12551262
function getSymbolLinks(symbol: Symbol): SymbolLinks {
12561263
if (symbol.flags & SymbolFlags.Transient) return <TransientSymbol>symbol;
12571264
const id = getSymbolId(symbol);
1258-
return symbolLinks[id] || (symbolLinks[id] = {});
1265+
return symbolLinks[id] || (symbolLinks[id] = new (<any>SymbolLinks)());
12591266
}
12601267

12611268
function getNodeLinks(node: Node): NodeLinks {
12621269
const nodeId = getNodeId(node);
1263-
return nodeLinks[nodeId] || (nodeLinks[nodeId] = { flags: 0 } as NodeLinks);
1270+
return nodeLinks[nodeId] || (nodeLinks[nodeId] = new (<any>NodeLinks)());
12641271
}
12651272

12661273
function isGlobalSourceFile(node: Node) {

0 commit comments

Comments
 (0)