Skip to content

Commit 16951fe

Browse files
authored
Merge pull request relayjs#70 from gaearon/free-debug
Explicitly guard debug calls
2 parents 9b05184 + 2928a0b commit 16951fe

File tree

4 files changed

+60
-26
lines changed

4 files changed

+60
-26
lines changed

src/backend/agent.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,9 @@ export default class Agent extends EventEmitter {
365365
};
366366

367367
onHookOperations = (operations: Uint32Array) => {
368-
debug('onHookOperations', operations);
368+
if (__DEBUG__) {
369+
debug('onHookOperations', operations);
370+
}
369371

370372
// TODO:
371373
// The chrome.runtime does not currently support transferables; it forces JSON serialization.

src/backend/renderer.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,9 @@ export function attach(
735735
}
736736

737737
function mountFiber(fiber: Fiber, parentFiber: Fiber | null) {
738-
debug('mountFiber()', fiber, parentFiber);
738+
if (__DEBUG__) {
739+
debug('mountFiber()', fiber, parentFiber);
740+
}
739741

740742
const shouldEnqueueMount = !shouldFilterFiber(fiber);
741743

@@ -756,7 +758,9 @@ export function attach(
756758
fiber: Fiber,
757759
hasChildOrderChanged: boolean
758760
) {
759-
debug('enqueueUpdateIfNecessary()', fiber);
761+
if (__DEBUG__) {
762+
debug('enqueueUpdateIfNecessary()', fiber);
763+
}
760764

761765
const isProfilingSupported = fiber.hasOwnProperty('treeBaseDuration');
762766
if (isProfilingSupported) {
@@ -833,7 +837,9 @@ export function attach(
833837
prevFiber: Fiber,
834838
parentFiber: Fiber | null
835839
) {
836-
debug('enqueueUpdateIfNecessary()', nextFiber, parentFiber);
840+
if (__DEBUG__) {
841+
debug('enqueueUpdateIfNecessary()', nextFiber, parentFiber);
842+
}
837843

838844
const shouldEnqueueUpdate = !shouldFilterFiber(nextFiber);
839845

src/devtools/store.js

+27-11
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ export default class Store extends EventEmitter {
110110
constructor(bridge: Bridge, config?: Config) {
111111
super();
112112

113-
debug('constructor', 'subscribing to Bridge');
113+
if (__DEBUG__) {
114+
debug('constructor', 'subscribing to Bridge');
115+
}
114116

115117
if (config != null) {
116118
const {
@@ -433,7 +435,9 @@ export default class Store extends EventEmitter {
433435
operations = Uint32Array.from(Object.values(operations));
434436
}
435437

436-
debug('onBridgeOperations', operations);
438+
if (__DEBUG__) {
439+
debug('onBridgeOperations', operations);
440+
}
437441

438442
let haveRootsChanged = false;
439443

@@ -479,7 +483,9 @@ export default class Store extends EventEmitter {
479483
i = i + 3;
480484

481485
if (type === ElementTypeRoot) {
482-
debug('Add', `new root fiber ${id}`);
486+
if (__DEBUG__) {
487+
debug('Add', `new root fiber ${id}`);
488+
}
483489

484490
if (this._idToElement.has(id)) {
485491
// 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 {
532538
: utfDecodeString((operations.slice(i, i + keyLength): any));
533539
i += +keyLength;
534540

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+
}
539547

540548
if (this._idToElement.has(id)) {
541549
// The renderer's tree walking approach sometimes mounts the same Fiber twice with Suspense and Lazy.
@@ -582,15 +590,19 @@ export default class Store extends EventEmitter {
582590

583591
parentElement = ((this._idToElement.get(parentID): any): Element);
584592
if (parentElement == null) {
585-
debug('Remove', `fiber ${id} root`);
593+
if (__DEBUG__) {
594+
debug('Remove', `fiber ${id} root`);
595+
}
586596

587597
this._roots = this._roots.filter(rootID => rootID !== id);
588598
this._rootIDToRendererID.delete(id);
589599
this._rootIDToCapabilities.delete(id);
590600

591601
haveRootsChanged = true;
592602
} else {
593-
debug('Remove', `fiber ${id} from parent ${parentID}`);
603+
if (__DEBUG__) {
604+
debug('Remove', `fiber ${id} from parent ${parentID}`);
605+
}
594606

595607
parentElement.children = parentElement.children.filter(
596608
childID => childID !== id
@@ -613,7 +625,9 @@ export default class Store extends EventEmitter {
613625

614626
i = i + 3 + numChildren;
615627

616-
debug('Re-order', `fiber ${id} children ${children.join(',')}`);
628+
if (__DEBUG__) {
629+
debug('Re-order', `fiber ${id} children ${children.join(',')}`);
630+
}
617631

618632
element = ((this._idToElement.get(id): any): Element);
619633
element.children = Array.from(children);
@@ -692,7 +706,9 @@ export default class Store extends EventEmitter {
692706
};
693707

694708
onBridgeShutdown = () => {
695-
debug('onBridgeShutdown', 'unsubscribing from Bridge');
709+
if (__DEBUG__) {
710+
debug('onBridgeShutdown', 'unsubscribing from Bridge');
711+
}
696712

697713
this._bridge.removeListener('operations', this.onBridgeOperations);
698714
this._bridge.removeListener('profilingStatus', this.onProfilingStatus);

src/devtools/views/Profiler/CommitTreeBuilder.js

+21-11
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ function updateTree(
186186
if (type === ElementTypeRoot) {
187187
i++; // supportsProfiling flag
188188

189-
debug('Add', `new root fiber ${id}`);
189+
if (__DEBUG__) {
190+
debug('Add', `new root fiber ${id}`);
191+
}
190192

191193
if (nodes.has(id)) {
192194
// The renderer's tree walking approach sometimes mounts the same Fiber twice with Suspense and Lazy.
@@ -233,10 +235,12 @@ function updateTree(
233235
// For now, we avoid adding it to the tree twice by checking if it's already been mounted.
234236
// Maybe in the future we'll revisit this.
235237
} 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+
}
240244

241245
parentNode = getClonedNode(parentID);
242246
parentNode.children = parentNode.children.concat(id);
@@ -268,7 +272,9 @@ function updateTree(
268272
if (parentNode == null) {
269273
// No-op
270274
} else {
271-
debug('Remove', `fiber ${id} from parent ${parentID}`);
275+
if (__DEBUG__) {
276+
debug('Remove', `fiber ${id} from parent ${parentID}`);
277+
}
272278

273279
parentNode.children = parentNode.children.filter(
274280
childID => childID !== id
@@ -285,7 +291,9 @@ function updateTree(
285291

286292
i = i + 3 + numChildren;
287293

288-
debug('Re-order', `fiber ${id} children ${children.join(',')}`);
294+
if (__DEBUG__) {
295+
debug('Re-order', `fiber ${id} children ${children.join(',')}`);
296+
}
289297

290298
node = getClonedNode(id);
291299
node.children = Array.from(children);
@@ -297,10 +305,12 @@ function updateTree(
297305
node = getClonedNode(id);
298306
node.treeBaseDuration = operations[i + 2] / 1000; // Convert microseconds back to milliseconds;
299307

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+
}
304314

305315
i = i + 3;
306316
break;

0 commit comments

Comments
 (0)