Added production profiling bundle type (#12886)
* Added profiling bundle * Turned profiling on for React Fabric OSS profiling and dev bundles * Added new global var "__PROFILE__" for profiling DCE
Brian Vaughn committed
Jun 11, 2018 at 13:16 UTC
d5c11193e2e6d5ea2d55ce3b428616c401310731
11 files changed
+95
-5
.eslintrc.js
+1
@@ -81,5 +81,6 @@ module.exports = {
81
spyOnDev: true,
82
spyOnDevAndProd: true,
83
spyOnProd: true,
84
+ __PROFILE__: true,
85
},
86
};
packages/shared/ReactFeatureFlags.js
+1
-1
@@ -37,7 +37,7 @@ export const warnAboutDeprecatedLifecycles = false;
37
export const warnAboutLegacyContextAPI = false;
38
39
// Gather advanced timing metrics for Profiler subtrees.
40
-export const enableProfilerTimer = __DEV__;
40
+export const enableProfilerTimer = __PROFILE__;
41
42
// Fires getDerivedStateFromProps for state *or* props changes
43
export const fireGetDerivedStateFromPropsOnStateUpdates = true;
packages/shared/forks/ReactFeatureFlags.native-fabric-oss.js
+1
-1
@@ -20,7 +20,7 @@ export const enableSuspense = false;
20
export const warnAboutDeprecatedLifecycles = false;
21
export const warnAboutLegacyContextAPI = false;
22
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
23
-export const enableProfilerTimer = false;
23
+export const enableProfilerTimer = __PROFILE__;
24
export const fireGetDerivedStateFromPropsOnStateUpdates = true;
25
26
// Only used in www builds.
packages/shared/forks/ReactFeatureFlags.native-oss.js
+1
-1
@@ -20,7 +20,7 @@ export const enableUserTimingAPI = __DEV__;
20
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
21
export const warnAboutDeprecatedLifecycles = false;
22
export const warnAboutLegacyContextAPI = false;
23
-export const enableProfilerTimer = __DEV__;
23
+export const enableProfilerTimer = __PROFILE__;
24
export const fireGetDerivedStateFromPropsOnStateUpdates = true;
25
26
// Only used in www builds.
scripts/flow/environment.js
+2
@@ -9,6 +9,8 @@
9
10
/* eslint-disable */
11
12
+declare var __PROFILE__: boolean;
13
+
14
declare var __REACT_DEVTOOLS_GLOBAL_HOOK__: any; /*?{
15
inject: ?((stuff: Object) => void)
16
};*/
scripts/jest/setupEnvironment.js
+1
@@ -5,6 +5,7 @@ if (NODE_ENV !== 'development' && NODE_ENV !== 'production') {
5
throw new Error('NODE_ENV must either be set to development or production.');
6
}
7
global.__DEV__ = NODE_ENV === 'development';
8
+global.__PROFILE__ = NODE_ENV === 'development';
9
10
global.requestAnimationFrame = function(callback) {
11
setTimeout(callback);
scripts/rollup/build.js
+38
@@ -39,10 +39,12 @@ const {
39
UMD_PROD,
40
NODE_DEV,
41
NODE_PROD,
42
+ NODE_PROFILING,
43
FB_WWW_DEV,
44
FB_WWW_PROD,
45
RN_OSS_DEV,
46
RN_OSS_PROD,
47
+ RN_OSS_PROFILING,
48
RN_FB_DEV,
49
RN_FB_PROD,
50
} = Bundles.bundleTypes;
@@ -95,6 +97,7 @@ function getBabelConfig(updateBabelOptions, bundleType, filename) {
97
});
98
case RN_OSS_DEV:
99
case RN_OSS_PROD:
100
+ case RN_OSS_PROFILING:
101
case RN_FB_DEV:
102
case RN_FB_PROD:
103
return Object.assign({}, options, {
@@ -107,6 +110,7 @@ function getBabelConfig(updateBabelOptions, bundleType, filename) {
110
case UMD_PROD:
111
case NODE_DEV:
112
case NODE_PROD:
113
+ case NODE_PROFILING:
114
return Object.assign({}, options, {
115
plugins: options.plugins.concat([
116
// Use object-assign polyfill in open source
@@ -152,10 +156,12 @@ function getFormat(bundleType) {
156
return `umd`;
157
case NODE_DEV:
158
case NODE_PROD:
159
+ case NODE_PROFILING:
160
case FB_WWW_DEV:
161
case FB_WWW_PROD:
162
case RN_OSS_DEV:
163
case RN_OSS_PROD:
164
+ case RN_OSS_PROFILING:
165
case RN_FB_DEV:
166
case RN_FB_PROD:
167
return `cjs`;
@@ -174,6 +180,8 @@ function getFilename(name, globalName, bundleType) {
180
return `${name}.development.js`;
181
case NODE_PROD:
182
return `${name}.production.min.js`;
183
+ case NODE_PROFILING:
184
+ return `${name}.profiling.min.js`;
185
case FB_WWW_DEV:
186
case RN_OSS_DEV:
187
case RN_FB_DEV:
@@ -182,6 +190,8 @@ function getFilename(name, globalName, bundleType) {
190
case RN_OSS_PROD:
191
case RN_FB_PROD:
192
return `${globalName}-prod.js`;
193
+ case RN_OSS_PROFILING:
194
+ return `${globalName}-profiling.js`;
195
}
196
}
197
@@ -195,8 +205,10 @@ function isProductionBundleType(bundleType) {
205
return false;
206
case UMD_PROD:
207
case NODE_PROD:
208
+ case NODE_PROFILING:
209
case FB_WWW_PROD:
210
case RN_OSS_PROD:
211
+ case RN_OSS_PROFILING:
212
case RN_FB_PROD:
213
return true;
214
default:
@@ -204,6 +216,27 @@ function isProductionBundleType(bundleType) {
216
}
217
}
218
219
+function isProfilingBundleType(bundleType) {
220
+ switch (bundleType) {
221
+ case FB_WWW_DEV:
222
+ case FB_WWW_PROD:
223
+ case NODE_DEV:
224
+ case NODE_PROD:
225
+ case RN_FB_DEV:
226
+ case RN_FB_PROD:
227
+ case RN_OSS_DEV:
228
+ case RN_OSS_PROD:
229
+ case UMD_DEV:
230
+ case UMD_PROD:
231
+ return false;
232
+ case NODE_PROFILING:
233
+ case RN_OSS_PROFILING:
234
+ return true;
235
+ default:
236
+ throw new Error(`Unknown type: ${bundleType}`);
237
+ }
238
+}
239
+
240
function getPlugins(
241
entry,
242
externals,
@@ -218,11 +251,13 @@ function getPlugins(
251
const findAndRecordErrorCodes = extractErrorCodes(errorCodeOpts);
252
const forks = Modules.getForks(bundleType, entry, moduleType);
253
const isProduction = isProductionBundleType(bundleType);
254
+ const isProfiling = isProfilingBundleType(bundleType);
255
const isInGlobalScope = bundleType === UMD_DEV || bundleType === UMD_PROD;
256
const isFBBundle = bundleType === FB_WWW_DEV || bundleType === FB_WWW_PROD;
257
const isRNBundle =
258
bundleType === RN_OSS_DEV ||
259
bundleType === RN_OSS_PROD ||
260
+ bundleType === RN_OSS_PROFILING ||
261
bundleType === RN_FB_DEV ||
262
bundleType === RN_FB_PROD;
263
const shouldStayReadable = isFBBundle || isRNBundle || forcePrettyOutput;
@@ -255,6 +290,7 @@ function getPlugins(
290
// Turn __DEV__ and process.env checks into constants.
291
replace({
292
__DEV__: isProduction ? 'false' : 'true',
293
+ __PROFILE__: isProfiling || !isProduction ? 'true' : 'false',
294
'process.env.NODE_ENV': isProduction ? "'production'" : "'development'",
295
}),
296
// We still need CommonJS for external deps like object-assign.
@@ -508,10 +544,12 @@ async function buildEverything() {
544
await createBundle(bundle, UMD_PROD);
545
await createBundle(bundle, NODE_DEV);
546
await createBundle(bundle, NODE_PROD);
547
+ await createBundle(bundle, NODE_PROFILING);
548
await createBundle(bundle, FB_WWW_DEV);
549
await createBundle(bundle, FB_WWW_PROD);
550
await createBundle(bundle, RN_OSS_DEV);
551
await createBundle(bundle, RN_OSS_PROD);
552
+ await createBundle(bundle, RN_OSS_PROFILING);
553
await createBundle(bundle, RN_FB_DEV);
554
await createBundle(bundle, RN_FB_PROD);
555
}
scripts/rollup/bundles.js
+7
-2
@@ -5,10 +5,12 @@ const bundleTypes = {
5
UMD_PROD: 'UMD_PROD',
6
NODE_DEV: 'NODE_DEV',
7
NODE_PROD: 'NODE_PROD',
8
+ NODE_PROFILING: 'NODE_PROFILING',
9
FB_WWW_DEV: 'FB_WWW_DEV',
10
FB_WWW_PROD: 'FB_WWW_PROD',
11
RN_OSS_DEV: 'RN_OSS_DEV',
12
RN_OSS_PROD: 'RN_OSS_PROD',
13
+ RN_OSS_PROFILING: 'RN_OSS_PROFILING',
14
RN_FB_DEV: 'RN_FB_DEV',
15
RN_FB_PROD: 'RN_FB_PROD',
16
};
@@ -17,10 +19,12 @@ const UMD_DEV = bundleTypes.UMD_DEV;
19
const UMD_PROD = bundleTypes.UMD_PROD;
20
const NODE_DEV = bundleTypes.NODE_DEV;
21
const NODE_PROD = bundleTypes.NODE_PROD;
22
+const NODE_PROFILING = bundleTypes.NODE_PROFILING;
23
const FB_WWW_DEV = bundleTypes.FB_WWW_DEV;
24
const FB_WWW_PROD = bundleTypes.FB_WWW_PROD;
25
const RN_OSS_DEV = bundleTypes.RN_OSS_DEV;
26
const RN_OSS_PROD = bundleTypes.RN_OSS_PROD;
27
+const RN_OSS_PROFILING = bundleTypes.RN_OSS_PROFILING;
28
const RN_FB_DEV = bundleTypes.RN_FB_DEV;
29
const RN_FB_PROD = bundleTypes.RN_FB_PROD;
30
@@ -69,6 +73,7 @@ const bundles = [
73
UMD_PROD,
74
NODE_DEV,
75
NODE_PROD,
76
+ NODE_PROFILING,
77
FB_WWW_DEV,
78
FB_WWW_PROD,
79
],
@@ -175,7 +180,7 @@ const bundles = [
180
181
{
182
label: 'native',
178
- bundleTypes: [RN_OSS_DEV, RN_OSS_PROD],
183
+ bundleTypes: [RN_OSS_DEV, RN_OSS_PROD, RN_OSS_PROFILING],
184
moduleType: RENDERER,
185
entry: 'react-native-renderer',
186
global: 'ReactNativeRenderer',
@@ -217,7 +222,7 @@ const bundles = [
222
223
{
224
label: 'native-fabric',
220
- bundleTypes: [RN_OSS_DEV, RN_OSS_PROD],
225
+ bundleTypes: [RN_OSS_DEV, RN_OSS_PROD, RN_OSS_PROFILING],
226
moduleType: RENDERER,
227
entry: 'react-native-renderer/fabric',
228
global: 'ReactFabric',
scripts/rollup/forks.js
+4
@@ -10,6 +10,7 @@ const FB_WWW_DEV = bundleTypes.FB_WWW_DEV;
10
const FB_WWW_PROD = bundleTypes.FB_WWW_PROD;
11
const RN_OSS_DEV = bundleTypes.RN_OSS_DEV;
12
const RN_OSS_PROD = bundleTypes.RN_OSS_PROD;
13
+const RN_OSS_PROFILING = bundleTypes.RN_OSS_PROFILING;
14
const RN_FB_DEV = bundleTypes.RN_FB_DEV;
15
const RN_FB_PROD = bundleTypes.RN_FB_PROD;
16
const RENDERER = moduleTypes.RENDERER;
@@ -45,6 +46,7 @@ const forks = Object.freeze({
46
return 'shared/forks/ReactFeatureFlags.native-fb.js';
47
case RN_OSS_DEV:
48
case RN_OSS_PROD:
49
+ case RN_OSS_PROFILING:
50
return 'shared/forks/ReactFeatureFlags.native-oss.js';
51
default:
52
throw Error(
@@ -58,6 +60,7 @@ const forks = Object.freeze({
60
return 'shared/forks/ReactFeatureFlags.native-fabric-fb.js';
61
case RN_OSS_DEV:
62
case RN_OSS_PROD:
63
+ case RN_OSS_PROFILING:
64
return 'shared/forks/ReactFeatureFlags.native-fabric-oss.js';
65
default:
66
throw Error(
@@ -143,6 +146,7 @@ const forks = Object.freeze({
146
return 'react-reconciler/src/forks/ReactFiberErrorDialog.www.js';
147
case RN_OSS_DEV:
148
case RN_OSS_PROD:
149
+ case RN_OSS_PROFILING:
150
case RN_FB_DEV:
151
case RN_FB_PROD:
152
switch (entry) {
scripts/rollup/packaging.js
+4
@@ -14,10 +14,12 @@ const {
14
UMD_PROD,
15
NODE_DEV,
16
NODE_PROD,
17
+ NODE_PROFILING,
18
FB_WWW_DEV,
19
FB_WWW_PROD,
20
RN_OSS_DEV,
21
RN_OSS_PROD,
22
+ RN_OSS_PROFILING,
23
RN_FB_DEV,
24
RN_FB_PROD,
25
} = Bundles.bundleTypes;
@@ -33,6 +35,7 @@ function getBundleOutputPaths(bundleType, filename, packageName) {
35
switch (bundleType) {
36
case NODE_DEV:
37
case NODE_PROD:
38
+ case NODE_PROFILING:
39
return [`build/node_modules/${packageName}/cjs/${filename}`];
40
case UMD_DEV:
41
case UMD_PROD:
@@ -45,6 +48,7 @@ function getBundleOutputPaths(bundleType, filename, packageName) {
48
return [`build/facebook-www/${filename}`];
49
case RN_OSS_DEV:
50
case RN_OSS_PROD:
51
+ case RN_OSS_PROFILING:
52
switch (packageName) {
53
case 'react-native-renderer':
54
return [`build/react-native/oss/${filename}`];
scripts/rollup/wrappers.js
+35
@@ -7,10 +7,12 @@ const UMD_DEV = Bundles.bundleTypes.UMD_DEV;
7
const UMD_PROD = Bundles.bundleTypes.UMD_PROD;
8
const NODE_DEV = Bundles.bundleTypes.NODE_DEV;
9
const NODE_PROD = Bundles.bundleTypes.NODE_PROD;
10
+const NODE_PROFILING = Bundles.bundleTypes.NODE_PROFILING;
11
const FB_WWW_DEV = Bundles.bundleTypes.FB_WWW_DEV;
12
const FB_WWW_PROD = Bundles.bundleTypes.FB_WWW_PROD;
13
const RN_OSS_DEV = Bundles.bundleTypes.RN_OSS_DEV;
14
const RN_OSS_PROD = Bundles.bundleTypes.RN_OSS_PROD;
15
+const RN_OSS_PROFILING = Bundles.bundleTypes.RN_OSS_PROFILING;
16
const RN_FB_DEV = Bundles.bundleTypes.RN_FB_DEV;
17
const RN_FB_PROD = Bundles.bundleTypes.RN_FB_PROD;
18
@@ -91,6 +93,25 @@ ${
93
${source}`;
94
},
95
96
+ /***************** NODE_PROFILING *****************/
97
+ [NODE_PROFILING](source, globalName, filename, moduleType) {
98
+ return `/** @license React v${reactVersion}
99
+ * ${filename}
100
+ *
101
+${license}
102
+ */
103
+${
104
+ globalName === 'ReactNoopRenderer' ||
105
+ globalName === 'ReactNoopRendererPersistent'
106
+ ? // React Noop needs regenerator runtime because it uses
107
+ // generators but GCC doesn't handle them in the output.
108
+ // So we use Babel for them.
109
+ `const regeneratorRuntime = require("regenerator-runtime");`
110
+ : ``
111
+ }
112
+${source}`;
113
+ },
114
+
115
/****************** FB_WWW_DEV ******************/
116
[FB_WWW_DEV](source, globalName, filename, moduleType) {
117
return `/**
@@ -154,6 +175,20 @@ ${license}
175
* ${'@gen' + 'erated'}
176
*/
177
178
+${source}`;
179
+ },
180
+
181
+ /****************** RN_OSS_PROFILING ******************/
182
+ [RN_OSS_PROFILING](source, globalName, filename, moduleType) {
183
+ return `/**
184
+${license}
185
+ *
186
+ * @noflow
187
+ * @providesModule ${globalName}-profiling
188
+ * @preventMunge
189
+ * ${'@gen' + 'erated'}
190
+ */
191
+
192
${source}`;
193
},
194