Skip to content

Commit 6011176

Browse files
Automatic perf stats in baselines (#57730)
1 parent aeddd65 commit 6011176

File tree

149 files changed

+933
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+933
-1
lines changed

src/harness/harnessIO.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,12 +776,57 @@ export namespace Compiler {
776776

777777
function generateBaseLine(isSymbolBaseline: boolean, skipBaseline?: boolean): string | null {
778778
let result = "";
779+
const perfLines: string[] = [];
780+
const prePerformanceValues = getPerformanceBaselineValues();
779781
const gen = iterateBaseLine(isSymbolBaseline, skipBaseline);
780782
for (const value of gen) {
781783
const [, content] = value;
782784
result += content;
783785
}
784-
return result ? (`//// [${header}] ////\r\n\r\n` + result) : null; // eslint-disable-line no-null/no-null
786+
const postPerformanceValues = getPerformanceBaselineValues();
787+
788+
if (!isSymbolBaseline) {
789+
const perfStats: [name: string, reportThreshold: number, rounding: number, beforeValue: number, afterValue: number][] = [];
790+
perfStats.push(["Strict subtype cache", 1000, 100, prePerformanceValues.strictSubtype, postPerformanceValues.strictSubtype]);
791+
perfStats.push(["Subtype cache", 1000, 100, prePerformanceValues.subtype, postPerformanceValues.subtype]);
792+
perfStats.push(["Identity cache", 1000, 100, prePerformanceValues.identity, postPerformanceValues.identity]);
793+
perfStats.push(["Assignability cache", 1000, 100, prePerformanceValues.assignability, postPerformanceValues.assignability]);
794+
perfStats.push(["Type Count", 1000, 100, prePerformanceValues.typeCount, postPerformanceValues.typeCount]);
795+
perfStats.push(["Instantiation count", 1500, 500, prePerformanceValues.instantiation, postPerformanceValues.instantiation]);
796+
perfStats.push(["Symbol count", 45000, 500, prePerformanceValues.symbol, postPerformanceValues.symbol]);
797+
798+
if (perfStats.some(([, threshold, , , postValue]) => postValue >= threshold)) {
799+
perfLines.push(`=== Performance Stats ===`);
800+
for (const [name, _, rounding, preValue, postValue] of perfStats) {
801+
const preDisplay = valueToString(preValue, rounding);
802+
if (preDisplay !== "0") {
803+
perfLines.push(`${name}: ${preDisplay} / ${valueToString(postValue, rounding)} (nearest ${rounding})`);
804+
}
805+
}
806+
perfLines.push("");
807+
perfLines.push("");
808+
}
809+
}
810+
811+
return result ? (`//// [${header}] ////\r\n\r\n${perfLines.join("\n")}${result}`) : null; // eslint-disable-line no-null/no-null
812+
}
813+
814+
function valueToString(value: number, rounding: number) {
815+
return (Math.round(value / rounding) * rounding).toLocaleString("en-US");
816+
}
817+
818+
function getPerformanceBaselineValues() {
819+
const checker = program.getTypeChecker();
820+
const caches = checker.getRelationCacheSizes();
821+
return {
822+
strictSubtype: caches.strictSubtype,
823+
subtype: caches.subtype,
824+
identity: caches.identity,
825+
assignability: caches.assignable,
826+
typeCount: checker.getTypeCount(),
827+
instantiation: checker.getInstantiationCount(),
828+
symbol: checker.getSymbolCount(),
829+
};
785830
}
786831

787832
function* iterateBaseLine(isSymbolBaseline: boolean, skipBaseline?: boolean): IterableIterator<[string, string]> {

tests/baselines/reference/APILibCheck.types

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
//// [tests/cases/compiler/APILibCheck.ts] ////
22

3+
=== Performance Stats ===
4+
Identity cache: 100 / 100 (nearest 100)
5+
Assignability cache: 9,300 / 9,300 (nearest 100)
6+
Type Count: 22,500 / 22,500 (nearest 100)
7+
Instantiation count: 7,000 / 7,000 (nearest 500)
8+
Symbol count: 58,500 / 58,500 (nearest 500)
9+
310
=== index.ts ===
411
import ts = require("typescript");
512
>ts : typeof ts

tests/baselines/reference/awaitedType.types

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
//// [tests/cases/compiler/awaitedType.ts] ////
22

3+
=== Performance Stats ===
4+
Assignability cache: 200 / 200 (nearest 100)
5+
Type Count: 900 / 900 (nearest 100)
6+
Instantiation count: 26,000 / 26,000 (nearest 500)
7+
Symbol count: 31,500 / 31,500 (nearest 500)
8+
39
=== awaitedType.ts ===
410
type T1 = Awaited<number>;
511
>T1 : number

tests/baselines/reference/awaitedTypeStrictNull.types

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
//// [tests/cases/compiler/awaitedTypeStrictNull.ts] ////
22

3+
=== Performance Stats ===
4+
Identity cache: 100 / 100 (nearest 100)
5+
Assignability cache: 200 / 200 (nearest 100)
6+
Type Count: 700 / 700 (nearest 100)
7+
Instantiation count: 25,500 / 25,500 (nearest 500)
8+
Symbol count: 30,500 / 30,500 (nearest 500)
9+
310
=== awaitedTypeStrictNull.ts ===
411
type T1 = Awaited<number>;
512
>T1 : number

tests/baselines/reference/callsOnComplexSignatures.types

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
//// [tests/cases/compiler/callsOnComplexSignatures.tsx] ////
22

3+
=== Performance Stats ===
4+
Subtype cache: 100 / 100 (nearest 100)
5+
Assignability cache: 2,400 / 2,400 (nearest 100)
6+
Type Count: 8,200 / 8,200 (nearest 100)
7+
Instantiation count: 92,500 / 92,500 (nearest 500)
8+
Symbol count: 68,000 / 68,000 (nearest 500)
9+
310
=== callsOnComplexSignatures.tsx ===
411
/// <reference path="react16.d.ts" />
512
import React from "react";

tests/baselines/reference/checkJsxChildrenCanBeTupleType.types

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
//// [tests/cases/conformance/jsx/checkJsxChildrenCanBeTupleType.tsx] ////
22

3+
=== Performance Stats ===
4+
Assignability cache: 2,200 / 2,200 (nearest 100)
5+
Type Count: 7,800 / 7,800 (nearest 100)
6+
Instantiation count: 90,000 / 90,000 (nearest 500)
7+
Symbol count: 66,500 / 66,500 (nearest 500)
8+
39
=== checkJsxChildrenCanBeTupleType.tsx ===
410
/// <reference path="react16.d.ts" />
511

tests/baselines/reference/checkJsxChildrenProperty16.types

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
//// [tests/cases/conformance/jsx/checkJsxChildrenProperty16.tsx] ////
22

3+
=== Performance Stats ===
4+
Assignability cache: 2,200 / 2,200 (nearest 100)
5+
Type Count: 7,600 / 7,600 (nearest 100)
6+
Instantiation count: 89,500 / 89,500 (nearest 500)
7+
Symbol count: 66,000 / 66,000 (nearest 500)
8+
39
=== checkJsxChildrenProperty16.tsx ===
410
/// <reference path="react16.d.ts" />
511

tests/baselines/reference/checkJsxUnionSFXContextualTypeInferredCorrectly.types

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
//// [tests/cases/conformance/jsx/checkJsxUnionSFXContextualTypeInferredCorrectly.tsx] ////
22

3+
=== Performance Stats ===
4+
Assignability cache: 2,200 / 2,200 (nearest 100)
5+
Type Count: 7,600 / 7,600 (nearest 100)
6+
Instantiation count: 89,500 / 89,500 (nearest 500)
7+
Symbol count: 66,500 / 66,500 (nearest 500)
8+
39
=== checkJsxUnionSFXContextualTypeInferredCorrectly.tsx ===
410
/// <reference path="react16.d.ts" />
511

tests/baselines/reference/circularBaseConstraint.types

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
//// [tests/cases/compiler/circularBaseConstraint.ts] ////
22

3+
=== Performance Stats ===
4+
Assignability cache: 100 / 100 (nearest 100)
5+
Type Count: 600 / 600 (nearest 100)
6+
Instantiation count: 2,000 / 2,000 (nearest 500)
7+
Symbol count: 25,500 / 25,500 (nearest 500)
8+
39
=== circularBaseConstraint.ts ===
410
// Repro from #54610
511

tests/baselines/reference/circularlySimplifyingConditionalTypesNoCrash.types

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
//// [tests/cases/compiler/circularlySimplifyingConditionalTypesNoCrash.ts] ////
22

3+
=== Performance Stats ===
4+
Assignability cache: 300 / 300 (nearest 100)
5+
Type Count: 600 / 600 (nearest 100)
6+
Instantiation count: 2,000 / 2,000 (nearest 500)
7+
Symbol count: 25,500 / 25,500 (nearest 500)
8+
39
=== circularlySimplifyingConditionalTypesNoCrash.ts ===
410
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
511
>Omit : Omit<T, K>

0 commit comments

Comments
 (0)