Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic perf stats in baselines #57730

Merged
merged 10 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion src/harness/harnessIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -776,12 +776,57 @@ export namespace Compiler {

function generateBaseLine(isSymbolBaseline: boolean, skipBaseline?: boolean): string | null {
let result = "";
const perfLines: string[] = [];
const prePerformanceValues = getPerformanceBaselineValues();
const gen = iterateBaseLine(isSymbolBaseline, skipBaseline);
for (const value of gen) {
const [, content] = value;
result += content;
}
return result ? (`//// [${header}] ////\r\n\r\n` + result) : null; // eslint-disable-line no-null/no-null
const postPerformanceValues = getPerformanceBaselineValues();

if (!isSymbolBaseline) {
const perfStats: [name: string, reportThreshold: number, rounding: number, beforeValue: number, afterValue: number][] = [];
perfStats.push(["Strict subtype cache", 1000, 100, prePerformanceValues.strictSubtype, postPerformanceValues.strictSubtype]);
perfStats.push(["Subtype cache", 1000, 100, prePerformanceValues.subtype, postPerformanceValues.subtype]);
perfStats.push(["Identity cache", 1000, 100, prePerformanceValues.identity, postPerformanceValues.identity]);
perfStats.push(["Assignability cache", 1000, 100, prePerformanceValues.assignability, postPerformanceValues.assignability]);
perfStats.push(["Type Count", 1000, 100, prePerformanceValues.typeCount, postPerformanceValues.typeCount]);
perfStats.push(["Instantiation count", 1500, 500, prePerformanceValues.instantiation, postPerformanceValues.instantiation]);
perfStats.push(["Symbol count", 45000, 500, prePerformanceValues.symbol, postPerformanceValues.symbol]);

if (perfStats.some(([, threshold, , , postValue]) => postValue >= threshold)) {
perfLines.push(`=== Performance Stats ===`);
for (const [name, _, rounding, preValue, postValue] of perfStats) {
const preDisplay = valueToString(preValue, rounding);
if (preDisplay !== "0") {
perfLines.push(`${name}: ${preDisplay} / ${valueToString(postValue, rounding)} (nearest ${rounding})`);
}
}
perfLines.push("");
perfLines.push("");
}
}

return result ? (`//// [${header}] ////\r\n\r\n${perfLines.join("\n")}${result}`) : null; // eslint-disable-line no-null/no-null
}

function valueToString(value: number, rounding: number) {
return (Math.round(value / rounding) * rounding).toLocaleString("en-US");
}

function getPerformanceBaselineValues() {
const checker = program.getTypeChecker();
const caches = checker.getRelationCacheSizes();
return {
strictSubtype: caches.strictSubtype,
subtype: caches.subtype,
identity: caches.identity,
assignability: caches.assignable,
typeCount: checker.getTypeCount(),
instantiation: checker.getInstantiationCount(),
symbol: checker.getSymbolCount(),
};
}

function* iterateBaseLine(isSymbolBaseline: boolean, skipBaseline?: boolean): IterableIterator<[string, string]> {
Expand Down
7 changes: 7 additions & 0 deletions tests/baselines/reference/APILibCheck.types
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
//// [tests/cases/compiler/APILibCheck.ts] ////

=== Performance Stats ===
Identity cache: 100 / 100 (nearest 100)
Assignability cache: 9,300 / 9,300 (nearest 100)
Type Count: 22,500 / 22,500 (nearest 100)
Instantiation count: 7,000 / 7,000 (nearest 500)
Symbol count: 58,500 / 58,500 (nearest 500)

=== index.ts ===
import ts = require("typescript");
>ts : typeof ts
Expand Down
6 changes: 6 additions & 0 deletions tests/baselines/reference/awaitedType.types
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//// [tests/cases/compiler/awaitedType.ts] ////

=== Performance Stats ===
Assignability cache: 200 / 200 (nearest 100)
Type Count: 900 / 900 (nearest 100)
Instantiation count: 26,000 / 26,000 (nearest 500)
Symbol count: 31,500 / 31,500 (nearest 500)

=== awaitedType.ts ===
type T1 = Awaited<number>;
>T1 : number
Expand Down
7 changes: 7 additions & 0 deletions tests/baselines/reference/awaitedTypeStrictNull.types
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
//// [tests/cases/compiler/awaitedTypeStrictNull.ts] ////

=== Performance Stats ===
Identity cache: 100 / 100 (nearest 100)
Assignability cache: 200 / 200 (nearest 100)
Type Count: 700 / 700 (nearest 100)
Instantiation count: 25,500 / 25,500 (nearest 500)
Symbol count: 30,500 / 30,500 (nearest 500)

=== awaitedTypeStrictNull.ts ===
type T1 = Awaited<number>;
>T1 : number
Expand Down
7 changes: 7 additions & 0 deletions tests/baselines/reference/callsOnComplexSignatures.types
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
//// [tests/cases/compiler/callsOnComplexSignatures.tsx] ////

=== Performance Stats ===
Subtype cache: 100 / 100 (nearest 100)
Assignability cache: 2,400 / 2,400 (nearest 100)
Type Count: 8,200 / 8,200 (nearest 100)
Instantiation count: 92,500 / 92,500 (nearest 500)
Symbol count: 68,000 / 68,000 (nearest 500)

=== callsOnComplexSignatures.tsx ===
/// <reference path="react16.d.ts" />
import React from "react";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//// [tests/cases/conformance/jsx/checkJsxChildrenCanBeTupleType.tsx] ////

=== Performance Stats ===
Assignability cache: 2,200 / 2,200 (nearest 100)
Type Count: 7,800 / 7,800 (nearest 100)
Instantiation count: 90,000 / 90,000 (nearest 500)
Symbol count: 66,500 / 66,500 (nearest 500)

=== checkJsxChildrenCanBeTupleType.tsx ===
/// <reference path="react16.d.ts" />

Expand Down
6 changes: 6 additions & 0 deletions tests/baselines/reference/checkJsxChildrenProperty16.types
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//// [tests/cases/conformance/jsx/checkJsxChildrenProperty16.tsx] ////

=== Performance Stats ===
Assignability cache: 2,200 / 2,200 (nearest 100)
Type Count: 7,600 / 7,600 (nearest 100)
Instantiation count: 89,500 / 89,500 (nearest 500)
Symbol count: 66,000 / 66,000 (nearest 500)

=== checkJsxChildrenProperty16.tsx ===
/// <reference path="react16.d.ts" />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//// [tests/cases/conformance/jsx/checkJsxUnionSFXContextualTypeInferredCorrectly.tsx] ////

=== Performance Stats ===
Assignability cache: 2,200 / 2,200 (nearest 100)
Type Count: 7,600 / 7,600 (nearest 100)
Instantiation count: 89,500 / 89,500 (nearest 500)
Symbol count: 66,500 / 66,500 (nearest 500)

=== checkJsxUnionSFXContextualTypeInferredCorrectly.tsx ===
/// <reference path="react16.d.ts" />

Expand Down
6 changes: 6 additions & 0 deletions tests/baselines/reference/circularBaseConstraint.types
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//// [tests/cases/compiler/circularBaseConstraint.ts] ////

=== Performance Stats ===
Assignability cache: 100 / 100 (nearest 100)
Type Count: 600 / 600 (nearest 100)
Instantiation count: 2,000 / 2,000 (nearest 500)
Symbol count: 25,500 / 25,500 (nearest 500)

=== circularBaseConstraint.ts ===
// Repro from #54610

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//// [tests/cases/compiler/circularlySimplifyingConditionalTypesNoCrash.ts] ////

=== Performance Stats ===
Assignability cache: 300 / 300 (nearest 100)
Type Count: 600 / 600 (nearest 100)
Instantiation count: 2,000 / 2,000 (nearest 500)
Symbol count: 25,500 / 25,500 (nearest 500)

=== circularlySimplifyingConditionalTypesNoCrash.ts ===
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
>Omit : Omit<T, K>
Expand Down
7 changes: 7 additions & 0 deletions tests/baselines/reference/complexRecursiveCollections.types
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
//// [tests/cases/compiler/complexRecursiveCollections.ts] ////

=== Performance Stats ===
Identity cache: 600 / 600 (nearest 100)
Assignability cache: 7,600 / 7,600 (nearest 100)
Type Count: 53,300 / 53,300 (nearest 100)
Instantiation count: 178,000 / 178,000 (nearest 500)
Symbol count: 134,500 / 134,500 (nearest 500)

=== complex.ts ===
interface Ara<T> { t: T }
>t : T
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//// [tests/cases/compiler/conditionalTypeDoesntSpinForever.ts] ////

=== Performance Stats ===
Assignability cache: 600 / 600 (nearest 100)
Type Count: 1,400 / 1,600 (nearest 100)
Instantiation count: 3,500 / 4,000 (nearest 500)
Symbol count: 28,000 / 28,000 (nearest 500)

=== conditionalTypeDoesntSpinForever.ts ===
// A *self-contained* demonstration of the problem follows...
// Test this by running `tsc --target es6` on the command-line, rather than through another build tool such as Gulp, Webpack, etc.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//// [tests/cases/compiler/conditionalTypeVarianceBigArrayConstraintsPerformance.ts] ////

=== Performance Stats ===
Assignability cache: 1,300 / 1,300 (nearest 100)
Type Count: 5,900 / 5,900 (nearest 100)
Instantiation count: 76,500 / 76,500 (nearest 500)
Symbol count: 67,500 / 67,500 (nearest 500)

=== conditionalTypeVarianceBigArrayConstraintsPerformance.ts ===
/// <reference path="react16.d.ts" />

Expand Down
6 changes: 6 additions & 0 deletions tests/baselines/reference/conditionalTypes1.types
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//// [tests/cases/conformance/types/conditional/conditionalTypes1.ts] ////

=== Performance Stats ===
Assignability cache: 300 / 300 (nearest 100)
Type Count: 900 / 900 (nearest 100)
Instantiation count: 1,500 / 1,500 (nearest 500)
Symbol count: 26,000 / 26,500 (nearest 500)

=== conditionalTypes1.ts ===
type T00 = Exclude<"a" | "b" | "c" | "d", "a" | "c" | "f">; // "b" | "d"
>T00 : "b" | "d"
Expand Down
6 changes: 6 additions & 0 deletions tests/baselines/reference/contextuallyTypedJsxChildren.types
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//// [tests/cases/compiler/contextuallyTypedJsxChildren.tsx] ////

=== Performance Stats ===
Assignability cache: 2,200 / 2,200 (nearest 100)
Type Count: 7,800 / 7,800 (nearest 100)
Instantiation count: 90,000 / 90,000 (nearest 500)
Symbol count: 67,000 / 67,000 (nearest 500)

=== contextuallyTypedJsxChildren.tsx ===
/// <reference path="react16.d.ts" />

Expand Down
6 changes: 6 additions & 0 deletions tests/baselines/reference/controlFlowOptionalChain3.types
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//// [tests/cases/conformance/controlFlow/controlFlowOptionalChain3.tsx] ////

=== Performance Stats ===
Assignability cache: 2,100 / 2,100 (nearest 100)
Type Count: 7,600 / 7,600 (nearest 100)
Instantiation count: 89,500 / 89,500 (nearest 500)
Symbol count: 66,500 / 66,500 (nearest 500)

=== controlFlowOptionalChain3.tsx ===
/// <reference path="react16.d.ts" />

Expand Down
6 changes: 6 additions & 0 deletions tests/baselines/reference/correlatedUnions.types
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//// [tests/cases/compiler/correlatedUnions.ts] ////

=== Performance Stats ===
Assignability cache: 500 / 500 (nearest 100)
Type Count: 1,000 / 1,000 (nearest 100)
Instantiation count: 1,000 / 1,000 (nearest 500)
Symbol count: 26,500 / 26,500 (nearest 500)

=== correlatedUnions.ts ===
// Various repros from #30581

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//// [tests/cases/compiler/declarationEmitRecursiveConditionalAliasPreserved.ts] ////

=== Performance Stats ===
Assignability cache: 1,900 / 1,900 (nearest 100)
Type Count: 14,200 / 14,200 (nearest 100)
Instantiation count: 57,000 / 57,000 (nearest 500)
Symbol count: 49,000 / 49,000 (nearest 500)

=== input.d.ts ===
type _BuildPowersOf2LengthArrays<
>_BuildPowersOf2LengthArrays : _BuildPowersOf2LengthArrays<Length, AccumulatedArray>
Expand Down
6 changes: 6 additions & 0 deletions tests/baselines/reference/declarationsAndAssignments.types
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//// [tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts] ////

=== Performance Stats ===
Assignability cache: 100 / 100 (nearest 100)
Type Count: 500 / 1,200 (nearest 100)
Instantiation count: 500 / 500 (nearest 500)
Symbol count: 27,000 / 28,000 (nearest 500)

=== declarationsAndAssignments.ts ===
function f0() {
>f0 : () => void
Expand Down
6 changes: 6 additions & 0 deletions tests/baselines/reference/deepComparisons.types
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//// [tests/cases/compiler/deepComparisons.ts] ////

=== Performance Stats ===
Assignability cache: 300 / 300 (nearest 100)
Type Count: 2,000 / 2,100 (nearest 100)
Instantiation count: 3,500 / 3,500 (nearest 500)
Symbol count: 26,500 / 27,000 (nearest 500)

=== deepComparisons.ts ===
function f1<T, K1 extends keyof T, K2 extends keyof T[K1]>() {
>f1 : <T, K1 extends keyof T, K2 extends keyof T[K1]>() => void
Expand Down
6 changes: 6 additions & 0 deletions tests/baselines/reference/deeplyNestedMappedTypes.types
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//// [tests/cases/compiler/deeplyNestedMappedTypes.ts] ////

=== Performance Stats ===
Assignability cache: 500 / 600 (nearest 100)
Type Count: 1,500 / 1,500 (nearest 100)
Instantiation count: 15,500 / 15,500 (nearest 500)
Symbol count: 26,000 / 26,000 (nearest 500)

=== deeplyNestedMappedTypes.ts ===
// Simplified repro from #55535

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//// [tests/cases/conformance/controlFlow/dependentDestructuredVariables.ts] ////

=== Performance Stats ===
Assignability cache: 300 / 300 (nearest 100)
Type Count: 2,200 / 2,300 (nearest 100)
Instantiation count: 1,500 / 1,500 (nearest 500)
Symbol count: 34,000 / 34,000 (nearest 500)

=== dependentDestructuredVariables.ts ===
type Action =
>Action : { kind: 'A'; payload: number; } | { kind: 'B'; payload: string; }
Expand Down
6 changes: 6 additions & 0 deletions tests/baselines/reference/duplicateNumericIndexers.types
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//// [tests/cases/conformance/types/members/duplicateNumericIndexers.ts] ////

=== Performance Stats ===
Assignability cache: 3,600 / 3,600 (nearest 100)
Type Count: 12,600 / 12,600 (nearest 100)
Instantiation count: 2,500 / 2,500 (nearest 500)
Symbol count: 29,000 / 29,000 (nearest 500)

=== duplicateNumericIndexers.ts ===
// it is an error to have duplicate index signatures of the same kind in a type

Expand Down
4 changes: 4 additions & 0 deletions tests/baselines/reference/enumLiteralsSubtypeReduction.types
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
//// [tests/cases/compiler/enumLiteralsSubtypeReduction.ts] ////

=== Performance Stats ===
Type Count: 3,200 / 3,200 (nearest 100)
Symbol count: 26,500 / 26,500 (nearest 500)

=== enumLiteralsSubtypeReduction.ts ===
enum E {
>E : E
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//// [tests/cases/compiler/errorInfoForRelatedIndexTypesNoConstraintElaboration.ts] ////

=== Performance Stats ===
Assignability cache: 2,300 / 2,300 (nearest 100)
Type Count: 10,100 / 10,100 (nearest 100)
Instantiation count: 229,000 / 229,000 (nearest 500)
Symbol count: 105,500 / 105,500 (nearest 500)

=== errorInfoForRelatedIndexTypesNoConstraintElaboration.ts ===
/// <reference path="react16.d.ts" />

Expand Down
6 changes: 6 additions & 0 deletions tests/baselines/reference/excessiveStackDepthFlatArray.types
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//// [tests/cases/compiler/excessiveStackDepthFlatArray.ts] ////

=== Performance Stats ===
Assignability cache: 200 / 200 (nearest 100)
Type Count: 900 / 900 (nearest 100)
Instantiation count: 1,500 / 1,500 (nearest 500)
Symbol count: 28,000 / 28,000 (nearest 500)

=== index.tsx ===
interface MiddlewareArray<T> extends Array<T> {}
declare function configureStore(options: { middleware: MiddlewareArray<any> }): void;
Expand Down
5 changes: 5 additions & 0 deletions tests/baselines/reference/excessivelyLargeTupleSpread.types
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
//// [tests/cases/compiler/excessivelyLargeTupleSpread.ts] ////

=== Performance Stats ===
Type Count: 33,100 / 33,100 (nearest 100)
Instantiation count: 49,500 / 49,500 (nearest 500)
Symbol count: 108,000 / 108,000 (nearest 500)

=== excessivelyLargeTupleSpread.ts ===
// #41771

Expand Down
4 changes: 4 additions & 0 deletions tests/baselines/reference/fixSignatureCaching.types
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
//// [tests/cases/conformance/fixSignatureCaching.ts] ////

=== Performance Stats ===
Type Count: 1,300 / 1,300 (nearest 100)
Symbol count: 26,500 / 27,000 (nearest 500)

=== fixSignatureCaching.ts ===
// Repro from #10697

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//// [tests/cases/compiler/flatArrayNoExcessiveStackDepth.ts] ////

=== Performance Stats ===
Assignability cache: 200 / 200 (nearest 100)
Type Count: 1,100 / 1,100 (nearest 100)
Instantiation count: 2,500 / 2,500 (nearest 500)
Symbol count: 31,000 / 31,000 (nearest 500)

=== flatArrayNoExcessiveStackDepth.ts ===
// Repro from #43493

Expand Down
Loading
Loading