Skip to content

Commit f11f001

Browse files
alexeylangfacebook-github-bot
authored andcommitted
Gate more code with if (__DEV__) { }
Reviewed By: amnn Differential Revision: D5621165 fbshipit-source-id: ee8b3df523858323a3ce4484ab56fcae0da3d633
1 parent 419652d commit f11f001

File tree

1 file changed

+51
-53
lines changed

1 file changed

+51
-53
lines changed

Libraries/Performance/Systrace.js

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -39,60 +39,56 @@ let _useFiber = false;
3939
// Implements a subset of User Timing API necessary for React measurements.
4040
// https://developer.mozilla.org/en-US/docs/Web/API/User_Timing_API
4141
const REACT_MARKER = '\u269B';
42-
const userTimingPolyfill = {
42+
const userTimingPolyfill = __DEV__ ? {
4343
mark(markName: string) {
44-
if (__DEV__) {
45-
if (_enabled) {
46-
_markStackIndex++;
47-
_markStack[_markStackIndex] = markName;
48-
let systraceLabel = markName;
49-
// Since perf measurements are a shared namespace in User Timing API,
50-
// we prefix all React results with a React emoji.
51-
if (markName[0] === REACT_MARKER) {
52-
// This is coming from React.
53-
// Removing component IDs keeps trace colors stable.
54-
const indexOfId = markName.lastIndexOf(' (#');
55-
const cutoffIndex = indexOfId !== -1 ? indexOfId : markName.length;
56-
// Also cut off the emoji because it breaks Systrace
57-
systraceLabel = markName.slice(2, cutoffIndex);
58-
}
59-
Systrace.beginEvent(systraceLabel);
44+
if (_enabled) {
45+
_markStackIndex++;
46+
_markStack[_markStackIndex] = markName;
47+
let systraceLabel = markName;
48+
// Since perf measurements are a shared namespace in User Timing API,
49+
// we prefix all React results with a React emoji.
50+
if (markName[0] === REACT_MARKER) {
51+
// This is coming from React.
52+
// Removing component IDs keeps trace colors stable.
53+
const indexOfId = markName.lastIndexOf(' (#');
54+
const cutoffIndex = indexOfId !== -1 ? indexOfId : markName.length;
55+
// Also cut off the emoji because it breaks Systrace
56+
systraceLabel = markName.slice(2, cutoffIndex);
6057
}
58+
Systrace.beginEvent(systraceLabel);
6159
}
6260
},
6361
measure(measureName: string, startMark: ?string, endMark: ?string) {
64-
if (__DEV__) {
65-
if (_enabled) {
66-
invariant(
67-
typeof measureName === 'string' &&
68-
typeof startMark === 'string' &&
69-
typeof endMark === 'undefined',
70-
'Only performance.measure(string, string) overload is supported.'
71-
);
72-
const topMark = _markStack[_markStackIndex];
73-
invariant(
74-
startMark === topMark,
75-
'There was a mismatching performance.measure() call. ' +
76-
'Expected "%s" but got "%s."',
77-
topMark,
78-
startMark,
79-
);
80-
_markStackIndex--;
81-
// We can't use more descriptive measureName because Systrace doesn't
82-
// let us edit labels post factum.
83-
Systrace.endEvent();
84-
}
62+
if (_enabled) {
63+
invariant(
64+
typeof measureName === 'string' &&
65+
typeof startMark === 'string' &&
66+
typeof endMark === 'undefined',
67+
'Only performance.measure(string, string) overload is supported.'
68+
);
69+
const topMark = _markStack[_markStackIndex];
70+
invariant(
71+
startMark === topMark,
72+
'There was a mismatching performance.measure() call. ' +
73+
'Expected "%s" but got "%s."',
74+
topMark,
75+
startMark,
76+
);
77+
_markStackIndex--;
78+
// We can't use more descriptive measureName because Systrace doesn't
79+
// let us edit labels post factum.
80+
Systrace.endEvent();
8581
}
8682
},
8783
clearMarks(markName: string) {
88-
if (__DEV__) {
89-
if (_enabled) {
90-
if (_markStackIndex === -1) {
91-
return;
92-
}
93-
if (markName === _markStack[_markStackIndex]) {
94-
// React uses this for "cancelling" started measurements.
95-
// Systrace doesn't support deleting measurements, so we just stop them.
84+
if (_enabled) {
85+
if (_markStackIndex === -1) {
86+
return;
87+
}
88+
if (markName === _markStack[_markStackIndex]) {
89+
// React uses this for "cancelling" started measurements.
90+
// Systrace doesn't support deleting measurements, so we just stop them.
91+
if (userTimingPolyfill != null) {
9692
userTimingPolyfill.measure(markName, markName);
9793
}
9894
}
@@ -102,10 +98,10 @@ const userTimingPolyfill = {
10298
// React calls this to avoid memory leaks in browsers, but we don't keep
10399
// measurements anyway.
104100
},
105-
};
101+
} : null;
106102

107103
// A hook to get React Stack markers in Systrace.
108-
const reactDebugToolHook = {
104+
const reactDebugToolHook = __DEV__ ? {
109105
onBeforeMountComponent(debugID) {
110106
const ReactComponentTreeHook = require('ReactGlobalSharedState').ReactComponentTreeHook;
111107
const displayName = ReactComponentTreeHook.getDisplayName(debugID);
@@ -138,15 +134,17 @@ const reactDebugToolHook = {
138134
onEndLifeCycleTimer(debugID, timerType) {
139135
Systrace.endEvent();
140136
},
141-
};
137+
} : null;
142138

143139
const Systrace = {
144140
installReactHook(useFiber: boolean) {
145141
if (_enabled) {
146-
if (useFiber) {
147-
global.performance = userTimingPolyfill;
148-
} else {
149-
require('ReactDebugTool').addHook(reactDebugToolHook);
142+
if (__DEV__) {
143+
if (useFiber) {
144+
global.performance = userTimingPolyfill;
145+
} else {
146+
require('ReactDebugTool').addHook(reactDebugToolHook);
147+
}
150148
}
151149
}
152150
_useFiber = useFiber;

0 commit comments

Comments
 (0)