log type evals perf when option is on (#7729)

This commit is contained in:
Heejae Chang 2024-04-19 18:11:58 -07:00 committed by GitHub
parent a8399d3933
commit 0127fd67ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 4 deletions

View File

@ -583,7 +583,13 @@ interface CodeFlowAnalyzerCacheEntry {
codeFlowAnalyzer: CodeFlowAnalyzer;
}
export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions: EvaluatorOptions): TypeEvaluator {
type LogWrapper = <T extends (...args: any[]) => any>(func: T) => (...args: Parameters<T>) => ReturnType<T>;
export function createTypeEvaluator(
importLookup: ImportLookup,
evaluatorOptions: EvaluatorOptions,
wrapWithLogger: LogWrapper
): TypeEvaluator {
const symbolResolutionStack: SymbolResolutionStackEntry[] = [];
const asymmetricAccessorAssignmentCache = new Set<number>();
const speculativeTypeTracker = new SpeculativeTypeTracker();
@ -21825,7 +21831,7 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
return UnknownType.create();
}
function getFunctionInferredReturnType(type: FunctionType, args?: ValidateArgTypeParams[]) {
function _getFunctionInferredReturnType(type: FunctionType, args?: ValidateArgTypeParams[]) {
let returnType: Type | undefined;
let isIncomplete = false;
const analyzeUnannotatedFunctions = true;
@ -26929,6 +26935,9 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
});
}
// Track these apis internal usages when logging is on. otherwise, it should be noop.
const getFunctionInferredReturnType = wrapWithLogger(_getFunctionInferredReturnType);
const evaluatorInterface: TypeEvaluator = {
runWithCancellationToken,
getType,

View File

@ -55,11 +55,14 @@ export function createTypeEvaluatorWithTracker(
// Wrap all functions with either a logger or a timer.
importLookup = wrapWithLogger(importLookup);
const evaluator = createTypeEvaluator(importLookup, evaluatorOptions);
const evaluator = createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger);
// Track these apis external usages when logging is on. otherwise, it should be noop.
const keys = Object.keys(evaluator);
keys.forEach((k) => {
const entry = (evaluator as any)[k];
if (typeof entry === 'function') {
if (typeof entry === 'function' && entry.name) {
// Only wrap functions that aren't wrapped already.
(evaluator as any)[k] = wrapWithLogger(entry);
}
});