mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[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.
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user