[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.
Joe Savona committed
Jan 17, 2023 at 16:00 UTC
de83adc739fd7dd5a699e0003627c876dee92c6b
1 file changed
+29
-3
compiler/forget/src/Utils/logger.ts
+29
-3
@@ -11,20 +11,46 @@ import { printReactiveFunction } from "../ReactiveScopes";
11
12
let ENABLED: boolean = false;
13
14
+let lastLogged: string;
15
+
16
export function toggleLogging(enabled: boolean) {
17
ENABLED = enabled;
18
}
19
20
export function logHIR(step: string, ir: HIR): void {
19
- log(() => `${step}:\n${printHIR(ir)}`);
21
+ if (ENABLED) {
22
+ const printed = printHIR(ir);
23
+ if (printed !== lastLogged) {
24
+ lastLogged = printed;
25
+ process.stdout.write(`${step}:\n${printed}\n\n`);
26
+ } else {
27
+ process.stdout.write(`${step}: (no change)\n\n`);
28
+ }
29
+ }
30
}
31
32
export function logHIRFunction(step: string, fn: HIRFunction): void {
23
- log(() => `${step}:\n${printFunction(fn)}`);
33
+ if (ENABLED) {
34
+ const printed = printFunction(fn);
35
+ if (printed !== lastLogged) {
36
+ lastLogged = printed;
37
+ process.stdout.write(`${step}:\n${printed}\n\n`);
38
+ } else {
39
+ process.stdout.write(`${step}: (no change)\n\n`);
40
+ }
41
+ }
42
}
43
44
export function logReactiveFunction(step: string, fn: ReactiveFunction): void {
27
- log(() => `${step}:\n${printReactiveFunction(fn)}`);
45
+ if (ENABLED) {
46
+ const printed = printReactiveFunction(fn);
47
+ if (printed !== lastLogged) {
48
+ lastLogged = printed;
49
+ process.stdout.write(`${step}:\n${printed}\n\n`);
50
+ } else {
51
+ process.stdout.write(`${step}: (no change)\n\n`);
52
+ }
53
+ }
54
}
55
56
export function log(fn: () => string) {