Skip to content

Logarithmish baseline counts #58212

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

Merged
merged 5 commits into from
Apr 16, 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
52 changes: 36 additions & 16 deletions src/harness/harnessIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -786,21 +786,27 @@ export namespace Compiler {
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)) {
const perfStats: [name: string, reportThreshold: number, beforeValue: number, afterValue: number][] = [];
perfStats.push(["Strict subtype cache", 1000, prePerformanceValues.strictSubtype, postPerformanceValues.strictSubtype]);
perfStats.push(["Subtype cache", 1000, prePerformanceValues.subtype, postPerformanceValues.subtype]);
perfStats.push(["Identity cache", 1000, prePerformanceValues.identity, postPerformanceValues.identity]);
perfStats.push(["Assignability cache", 1000, prePerformanceValues.assignability, postPerformanceValues.assignability]);
perfStats.push(["Type Count", 1000, prePerformanceValues.typeCount, postPerformanceValues.typeCount]);
perfStats.push(["Instantiation count", 1500, prePerformanceValues.instantiation, postPerformanceValues.instantiation]);
perfStats.push(["Symbol count", 45000, 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})`);
for (const [name, threshold, preValue, postValue] of perfStats) {
if (postValue >= threshold) {
const preString = valueToString(preValue);
const postString = valueToString(postValue);
if (preString === postString) {
perfLines.push(`${name}: ${preString}`);
}
else {
perfLines.push(`${name}: ${preString} -> ${postString}`);
}
}
}
perfLines.push("");
Expand All @@ -809,10 +815,24 @@ export namespace Compiler {
}

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

function valueToString(value: number) {
return roundToHumanLogarithm(value).toLocaleString("en-US");
}
}

function valueToString(value: number, rounding: number) {
return (Math.round(value / rounding) * rounding).toLocaleString("en-US");
/**
* Rounds to a number like 10, 25, 50, 100, 250, 500, 1000, etc
*/
function roundToHumanLogarithm(n: number) {
if (n < 10) return 0;
const powerOfTen = Math.floor(Math.log10(n));
const basePowerOfTen = Math.pow(10, powerOfTen);
const multipliers = [1, 2.5, 5, 10];
const closestMultiplier = multipliers.reduce((prev, curr) => {
return Math.abs(curr * basePowerOfTen - n) < Math.abs(prev * basePowerOfTen - n) ? curr : prev;
});
return closestMultiplier * basePowerOfTen;
}

function getPerformanceBaselineValues() {
Expand Down
5 changes: 1 addition & 4 deletions tests/baselines/reference/awaitedType.types
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
//// [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)
Instantiation count: 25,000

=== awaitedType.ts ===
type T1 = Awaited<number>;
Expand Down
6 changes: 1 addition & 5 deletions tests/baselines/reference/awaitedTypeStrictNull.types
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
//// [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)
Instantiation count: 25,000

=== awaitedTypeStrictNull.ts ===
type T1 = Awaited<number>;
Expand Down
9 changes: 4 additions & 5 deletions tests/baselines/reference/callsOnComplexSignatures.types
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
//// [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)
Assignability cache: 2,500
Type Count: 10,000
Instantiation count: 100,000
Symbol count: 50,000

=== callsOnComplexSignatures.tsx ===
/// <reference path="react16.d.ts" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//// [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: 67,000 / 67,000 (nearest 500)
Assignability cache: 2,500
Type Count: 10,000
Instantiation count: 100,000
Symbol count: 50,000

=== checkJsxChildrenCanBeTupleType.tsx ===
/// <reference path="react16.d.ts" />
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/checkJsxChildrenProperty16.types
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//// [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)
Assignability cache: 2,500
Type Count: 10,000
Instantiation count: 100,000
Symbol count: 50,000

=== checkJsxChildrenProperty16.tsx ===
/// <reference path="react16.d.ts" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//// [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)
Assignability cache: 2,500
Type Count: 10,000
Instantiation count: 100,000
Symbol count: 50,000

=== checkJsxUnionSFXContextualTypeInferredCorrectly.tsx ===
/// <reference path="react16.d.ts" />
Expand Down
5 changes: 1 addition & 4 deletions tests/baselines/reference/circularBaseConstraint.types
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
//// [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)
Instantiation count: 2,500

=== circularBaseConstraint.ts ===
// Repro from #54610
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
//// [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)
Instantiation count: 2,500

=== circularlySimplifyingConditionalTypesNoCrash.ts ===
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
Expand Down
9 changes: 4 additions & 5 deletions tests/baselines/reference/complexRecursiveCollections.types
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
//// [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)
Assignability cache: 10,000
Type Count: 50,000
Instantiation count: 250,000
Symbol count: 100,000

=== complex.ts ===
interface Ara<T> { t: T }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
//// [tests/cases/compiler/conditionalTypeDiscriminatingLargeUnionRegularTypeFetchingSpeedReasonable.ts] ////

=== Performance Stats ===
Strict subtype cache: 2,000 / 2,000 (nearest 100)
Assignability cache: 16,000 / 16,000 (nearest 100)
Type Count: 14,200 / 14,200 (nearest 100)
Instantiation count: 84,000 / 84,000 (nearest 500)
Symbol count: 33,500 / 33,500 (nearest 500)
Strict subtype cache: 2,500
Assignability cache: 10,000
Type Count: 10,000
Instantiation count: 100,000

=== conditionalTypeDiscriminatingLargeUnionRegularTypeFetchingSpeedReasonable.ts ===
type BigUnion =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
//// [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)
Type Count: 1,000
Instantiation count: 2,500 -> 5,000

=== conditionalTypeDoesntSpinForever.ts ===
// A *self-contained* demonstration of the problem follows...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//// [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)
Assignability cache: 1,000
Type Count: 5,000
Instantiation count: 100,000
Symbol count: 50,000

=== conditionalTypeVarianceBigArrayConstraintsPerformance.ts ===
/// <reference path="react16.d.ts" />
Expand Down
5 changes: 1 addition & 4 deletions tests/baselines/reference/conditionalTypes1.types
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
//// [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)
Instantiation count: 1,000

=== conditionalTypes1.ts ===
type T00 = Exclude<"a" | "b" | "c" | "d", "a" | "c" | "f">; // "b" | "d"
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/contextuallyTypedJsxChildren.types
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//// [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)
Assignability cache: 2,500
Type Count: 10,000
Instantiation count: 100,000
Symbol count: 50,000

=== contextuallyTypedJsxChildren.tsx ===
/// <reference path="react16.d.ts" />
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/controlFlowOptionalChain3.types
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//// [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)
Assignability cache: 2,500
Type Count: 10,000
Instantiation count: 100,000
Symbol count: 50,000

=== controlFlowOptionalChain3.tsx ===
/// <reference path="react16.d.ts" />
Expand Down
5 changes: 1 addition & 4 deletions tests/baselines/reference/correlatedUnions.types
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
//// [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)
Type Count: 1,000

=== correlatedUnions.ts ===
// Various repros from #30581
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//// [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)
Assignability cache: 2,500
Type Count: 10,000
Instantiation count: 50,000
Symbol count: 50,000

=== input.d.ts ===
type _BuildPowersOf2LengthArrays<
Expand Down
5 changes: 1 addition & 4 deletions tests/baselines/reference/declarationsAndAssignments.types
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
//// [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)
Type Count: 500 -> 1,000

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

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

=== deepComparisons.ts ===
function f1<T, K1 extends keyof T, K2 extends keyof T[K1]>() {
Expand Down
6 changes: 2 additions & 4 deletions tests/baselines/reference/deeplyNestedMappedTypes.types
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
//// [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)
Type Count: 1,000
Instantiation count: 10,000

=== deeplyNestedMappedTypes.ts ===
// Simplified repro from #55535
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
//// [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)
Type Count: 2,500
Instantiation count: 1,000

=== dependentDestructuredVariables.ts ===
type Action =
Expand Down
6 changes: 2 additions & 4 deletions tests/baselines/reference/divideAndConquerIntersections.types
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
//// [tests/cases/compiler/divideAndConquerIntersections.ts] ////

=== Performance Stats ===
Assignability cache: 100 / 100 (nearest 100)
Type Count: 2,800 / 2,900 (nearest 100)
Instantiation count: 7,500 / 7,500 (nearest 500)
Symbol count: 26,000 / 26,000 (nearest 500)
Type Count: 2,500
Instantiation count: 10,000

=== divideAndConquerIntersections.ts ===
type QQ<T extends string[]> =
Expand Down
7 changes: 3 additions & 4 deletions tests/baselines/reference/duplicateNumericIndexers.types
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//// [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)
Assignability cache: 2,500
Type Count: 10,000
Instantiation count: 2,500

=== duplicateNumericIndexers.ts ===
// it is an error to have duplicate index signatures of the same kind in a type
Expand Down
3 changes: 1 addition & 2 deletions tests/baselines/reference/enumLiteralsSubtypeReduction.types
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//// [tests/cases/compiler/enumLiteralsSubtypeReduction.ts] ////

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

=== enumLiteralsSubtypeReduction.ts ===
enum E {
Expand Down
Loading