Explicitly guard debug calls
Dan committed
Apr 5, 2019 at 00:03 UTC
2928a0be742babe9e971e252c2f96bb2dbf6c564
4 files changed
+60
-26
src/backend/agent.js
+3
-1
@@ -365,7 +365,9 @@ export default class Agent extends EventEmitter {
365
};
366
367
onHookOperations = (operations: Uint32Array) => {
368
- debug('onHookOperations', operations);
368
+ if (__DEBUG__) {
369
+ debug('onHookOperations', operations);
370
+ }
371
372
// TODO:
373
// The chrome.runtime does not currently support transferables; it forces JSON serialization.
src/backend/renderer.js
+9
-3
@@ -735,7 +735,9 @@ export function attach(
735
}
736
737
function mountFiber(fiber: Fiber, parentFiber: Fiber | null) {
738
- debug('mountFiber()', fiber, parentFiber);
738
+ if (__DEBUG__) {
739
+ debug('mountFiber()', fiber, parentFiber);
740
+ }
741
742
const shouldEnqueueMount = !shouldFilterFiber(fiber);
743
@@ -756,7 +758,9 @@ export function attach(
758
fiber: Fiber,
759
hasChildOrderChanged: boolean
760
) {
759
- debug('enqueueUpdateIfNecessary()', fiber);
761
+ if (__DEBUG__) {
762
+ debug('enqueueUpdateIfNecessary()', fiber);
763
+ }
764
765
const isProfilingSupported = fiber.hasOwnProperty('treeBaseDuration');
766
if (isProfilingSupported) {
@@ -833,7 +837,9 @@ export function attach(
837
prevFiber: Fiber,
838
parentFiber: Fiber | null
839
) {
836
- debug('enqueueUpdateIfNecessary()', nextFiber, parentFiber);
840
+ if (__DEBUG__) {
841
+ debug('enqueueUpdateIfNecessary()', nextFiber, parentFiber);
842
+ }
843
844
const shouldEnqueueUpdate = !shouldFilterFiber(nextFiber);
845
src/devtools/store.js
+27
-11
@@ -110,7 +110,9 @@ export default class Store extends EventEmitter {
110
constructor(bridge: Bridge, config?: Config) {
111
super();
112
113
- debug('constructor', 'subscribing to Bridge');
113
+ if (__DEBUG__) {
114
+ debug('constructor', 'subscribing to Bridge');
115
+ }
116
117
if (config != null) {
118
const {
@@ -433,7 +435,9 @@ export default class Store extends EventEmitter {
435
operations = Uint32Array.from(Object.values(operations));
436
}
437
436
- debug('onBridgeOperations', operations);
438
+ if (__DEBUG__) {
439
+ debug('onBridgeOperations', operations);
440
+ }
441
442
let haveRootsChanged = false;
443
@@ -479,7 +483,9 @@ export default class Store extends EventEmitter {
483
i = i + 3;
484
485
if (type === ElementTypeRoot) {
482
- debug('Add', `new root fiber ${id}`);
486
+ if (__DEBUG__) {
487
+ debug('Add', `new root fiber ${id}`);
488
+ }
489
490
if (this._idToElement.has(id)) {
491
// The renderer's tree walking approach sometimes mounts the same Fiber twice with Suspense and Lazy.
@@ -532,10 +538,12 @@ export default class Store extends EventEmitter {
538
: utfDecodeString((operations.slice(i, i + keyLength): any));
539
i += +keyLength;
540
535
- debug(
536
- 'Add',
537
- `fiber ${id} (${displayName || 'null'}) as child of ${parentID}`
538
- );
541
+ if (__DEBUG__) {
542
+ debug(
543
+ 'Add',
544
+ `fiber ${id} (${displayName || 'null'}) as child of ${parentID}`
545
+ );
546
+ }
547
548
if (this._idToElement.has(id)) {
549
// The renderer's tree walking approach sometimes mounts the same Fiber twice with Suspense and Lazy.
@@ -582,7 +590,9 @@ export default class Store extends EventEmitter {
590
591
parentElement = ((this._idToElement.get(parentID): any): Element);
592
if (parentElement == null) {
585
- debug('Remove', `fiber ${id} root`);
593
+ if (__DEBUG__) {
594
+ debug('Remove', `fiber ${id} root`);
595
+ }
596
597
this._roots = this._roots.filter(rootID => rootID !== id);
598
this._rootIDToRendererID.delete(id);
@@ -590,7 +600,9 @@ export default class Store extends EventEmitter {
600
601
haveRootsChanged = true;
602
} else {
593
- debug('Remove', `fiber ${id} from parent ${parentID}`);
603
+ if (__DEBUG__) {
604
+ debug('Remove', `fiber ${id} from parent ${parentID}`);
605
+ }
606
607
parentElement.children = parentElement.children.filter(
608
childID => childID !== id
@@ -613,7 +625,9 @@ export default class Store extends EventEmitter {
625
626
i = i + 3 + numChildren;
627
616
- debug('Re-order', `fiber ${id} children ${children.join(',')}`);
628
+ if (__DEBUG__) {
629
+ debug('Re-order', `fiber ${id} children ${children.join(',')}`);
630
+ }
631
632
element = ((this._idToElement.get(id): any): Element);
633
element.children = Array.from(children);
@@ -692,7 +706,9 @@ export default class Store extends EventEmitter {
706
};
707
708
onBridgeShutdown = () => {
695
- debug('onBridgeShutdown', 'unsubscribing from Bridge');
709
+ if (__DEBUG__) {
710
+ debug('onBridgeShutdown', 'unsubscribing from Bridge');
711
+ }
712
713
this._bridge.removeListener('operations', this.onBridgeOperations);
714
this._bridge.removeListener('profilingStatus', this.onProfilingStatus);
src/devtools/views/Profiler/CommitTreeBuilder.js
+21
-11
@@ -186,7 +186,9 @@ function updateTree(
186
if (type === ElementTypeRoot) {
187
i++; // supportsProfiling flag
188
189
- debug('Add', `new root fiber ${id}`);
189
+ if (__DEBUG__) {
190
+ debug('Add', `new root fiber ${id}`);
191
+ }
192
193
if (nodes.has(id)) {
194
// The renderer's tree walking approach sometimes mounts the same Fiber twice with Suspense and Lazy.
@@ -233,10 +235,12 @@ function updateTree(
235
// For now, we avoid adding it to the tree twice by checking if it's already been mounted.
236
// Maybe in the future we'll revisit this.
237
} else {
236
- debug(
237
- 'Add',
238
- `fiber ${id} (${displayName || 'null'}) as child of ${parentID}`
239
- );
238
+ if (__DEBUG__) {
239
+ debug(
240
+ 'Add',
241
+ `fiber ${id} (${displayName || 'null'}) as child of ${parentID}`
242
+ );
243
+ }
244
245
parentNode = getClonedNode(parentID);
246
parentNode.children = parentNode.children.concat(id);
@@ -268,7 +272,9 @@ function updateTree(
272
if (parentNode == null) {
273
// No-op
274
} else {
271
- debug('Remove', `fiber ${id} from parent ${parentID}`);
275
+ if (__DEBUG__) {
276
+ debug('Remove', `fiber ${id} from parent ${parentID}`);
277
+ }
278
279
parentNode.children = parentNode.children.filter(
280
childID => childID !== id
@@ -285,7 +291,9 @@ function updateTree(
291
292
i = i + 3 + numChildren;
293
288
- debug('Re-order', `fiber ${id} children ${children.join(',')}`);
294
+ if (__DEBUG__) {
295
+ debug('Re-order', `fiber ${id} children ${children.join(',')}`);
296
+ }
297
298
node = getClonedNode(id);
299
node.children = Array.from(children);
@@ -297,10 +305,12 @@ function updateTree(
305
node = getClonedNode(id);
306
node.treeBaseDuration = operations[i + 2] / 1000; // Convert microseconds back to milliseconds;
307
300
- debug(
301
- 'Update',
302
- `fiber ${id} treeBaseDuration to ${node.treeBaseDuration}`
303
- );
308
+ if (__DEBUG__) {
309
+ debug(
310
+ 'Update',
311
+ `fiber ${id} treeBaseDuration to ${node.treeBaseDuration}`
312
+ );
313
+ }
314
315
i = i + 3;
316
break;