From 72c0961071a29ab41e011b59bc50046c04b4d21e Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Sat, 14 Sep 2019 01:53:04 +0200 Subject: [PATCH 1/2] Force a gc before printing diagnostics Use this together with `node --expose-gc` to get more stable results --- src/tsc/tsc.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/tsc/tsc.ts b/src/tsc/tsc.ts index fc75e28d504..2e837a09594 100644 --- a/src/tsc/tsc.ts +++ b/src/tsc/tsc.ts @@ -322,6 +322,10 @@ namespace ts { const compilerOptions = program.getCompilerOptions(); if (compilerOptions.diagnostics || compilerOptions.extendedDiagnostics) { statistics = []; + + // @ts-ignore + if (typeof gc === "function") { gc(); } + const memoryUsed = sys.getMemoryUsage ? sys.getMemoryUsage() : -1; reportCountStatistic("Files", program.getSourceFiles().length); reportCountStatistic("Lines", countLines(program)); From 391a3c8791a8c56e283d39dd0f291156ed304d52 Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Sat, 14 Sep 2019 04:06:09 +0200 Subject: [PATCH 2/2] Separate Tokens and Identifiers from other Nodes With some further optimization to their properties, this shrinks the objects by quite a bit. --- src/compiler/utilities.ts | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index b338d3ba657..3032b1c3efc 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -3962,6 +3962,9 @@ namespace ts { } export function getModifierFlags(node: Node): ModifierFlags { + if (node.kind >= SyntaxKind.FirstToken && node.kind <= SyntaxKind.LastToken) { + return ModifierFlags.None; + } if (node.modifierFlagsCache & ModifierFlags.HasComputedFlags) { return node.modifierFlagsCache & ~ModifierFlags.HasComputedFlags; } @@ -7149,6 +7152,28 @@ namespace ts { this.original = undefined; } + function Token(this: Node, kind: SyntaxKind, pos: number, end: number) { + this.pos = pos; + this.end = end; + this.kind = kind; + this.id = 0; + this.flags = NodeFlags.None; + this.transformFlags = TransformFlags.None; + this.parent = undefined!; + } + + function Identifier(this: Node, kind: SyntaxKind, pos: number, end: number) { + this.pos = pos; + this.end = end; + this.kind = kind; + this.id = 0; + this.flags = NodeFlags.None; + this.transformFlags = TransformFlags.None; + this.parent = undefined!; + this.original = undefined; + this.flowNode = undefined; + } + function SourceMapSource(this: SourceMapSource, fileName: string, text: string, skipTrivia?: (pos: number) => number) { this.fileName = fileName; this.text = text; @@ -7158,8 +7183,8 @@ namespace ts { // eslint-disable-next-line prefer-const export let objectAllocator: ObjectAllocator = { getNodeConstructor: () => Node, - getTokenConstructor: () => Node, - getIdentifierConstructor: () => Node, + getTokenConstructor: () => Token, + getIdentifierConstructor: () => Identifier, getSourceFileConstructor: () => Node, getSymbolConstructor: () => Symbol, getTypeConstructor: () => Type,