From de83adc739fd7dd5a699e0003627c876dee92c6b Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Tue, 17 Jan 2023 16:00:42 -0800 Subject: [PATCH] [be] Skip debug logging if content has not changed Avoids printing debug information if it exactly matches what was last printed. This means when debug printing (eg with `@only`) you'll see things like: ``` BuildReactiveFunctions: ...debug view... FlattenReactiveLoops: (no change) PropagateScopeDependencies: ...debug view... ``` Which saves time figuring out if something changed in a given pass. --- compiler/forget/src/Utils/logger.ts | 32 ++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/compiler/forget/src/Utils/logger.ts b/compiler/forget/src/Utils/logger.ts index 42420a8cf9..dbdff8d137 100644 --- a/compiler/forget/src/Utils/logger.ts +++ b/compiler/forget/src/Utils/logger.ts @@ -11,20 +11,46 @@ import { printReactiveFunction } from "../ReactiveScopes"; let ENABLED: boolean = false; +let lastLogged: string; + export function toggleLogging(enabled: boolean) { ENABLED = enabled; } export function logHIR(step: string, ir: HIR): void { - log(() => `${step}:\n${printHIR(ir)}`); + if (ENABLED) { + const printed = printHIR(ir); + if (printed !== lastLogged) { + lastLogged = printed; + process.stdout.write(`${step}:\n${printed}\n\n`); + } else { + process.stdout.write(`${step}: (no change)\n\n`); + } + } } export function logHIRFunction(step: string, fn: HIRFunction): void { - log(() => `${step}:\n${printFunction(fn)}`); + if (ENABLED) { + const printed = printFunction(fn); + if (printed !== lastLogged) { + lastLogged = printed; + process.stdout.write(`${step}:\n${printed}\n\n`); + } else { + process.stdout.write(`${step}: (no change)\n\n`); + } + } } export function logReactiveFunction(step: string, fn: ReactiveFunction): void { - log(() => `${step}:\n${printReactiveFunction(fn)}`); + if (ENABLED) { + const printed = printReactiveFunction(fn); + if (printed !== lastLogged) { + lastLogged = printed; + process.stdout.write(`${step}:\n${printed}\n\n`); + } else { + process.stdout.write(`${step}: (no change)\n\n`); + } + } } export function log(fn: () => string) {