mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-25 05:29:07 -05:00
Automatic perf stats in baselines (#57730)
This commit is contained in:
@@ -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]> {
|
||||
|
||||
Reference in New Issue
Block a user