Skip to content

Commit d5c1119

Browse files
authored
Added production profiling bundle type (facebook#12886)
* Added profiling bundle * Turned profiling on for React Fabric OSS profiling and dev bundles * Added new global var "__PROFILE__" for profiling DCE
1 parent ec60457 commit d5c1119

File tree

11 files changed

+95
-5
lines changed

11 files changed

+95
-5
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,6 @@ module.exports = {
8181
spyOnDev: true,
8282
spyOnDevAndProd: true,
8383
spyOnProd: true,
84+
__PROFILE__: true,
8485
},
8586
};

packages/shared/ReactFeatureFlags.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const warnAboutDeprecatedLifecycles = false;
3737
export const warnAboutLegacyContextAPI = false;
3838

3939
// Gather advanced timing metrics for Profiler subtrees.
40-
export const enableProfilerTimer = __DEV__;
40+
export const enableProfilerTimer = __PROFILE__;
4141

4242
// Fires getDerivedStateFromProps for state *or* props changes
4343
export const fireGetDerivedStateFromPropsOnStateUpdates = true;

packages/shared/forks/ReactFeatureFlags.native-fabric-oss.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const enableSuspense = false;
2020
export const warnAboutDeprecatedLifecycles = false;
2121
export const warnAboutLegacyContextAPI = false;
2222
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
23-
export const enableProfilerTimer = false;
23+
export const enableProfilerTimer = __PROFILE__;
2424
export const fireGetDerivedStateFromPropsOnStateUpdates = true;
2525

2626
// Only used in www builds.

packages/shared/forks/ReactFeatureFlags.native-oss.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const enableUserTimingAPI = __DEV__;
2020
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
2121
export const warnAboutDeprecatedLifecycles = false;
2222
export const warnAboutLegacyContextAPI = false;
23-
export const enableProfilerTimer = __DEV__;
23+
export const enableProfilerTimer = __PROFILE__;
2424
export const fireGetDerivedStateFromPropsOnStateUpdates = true;
2525

2626
// Only used in www builds.

scripts/flow/environment.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
/* eslint-disable */
1111

12+
declare var __PROFILE__: boolean;
13+
1214
declare var __REACT_DEVTOOLS_GLOBAL_HOOK__: any; /*?{
1315
inject: ?((stuff: Object) => void)
1416
};*/

scripts/jest/setupEnvironment.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ if (NODE_ENV !== 'development' && NODE_ENV !== 'production') {
55
throw new Error('NODE_ENV must either be set to development or production.');
66
}
77
global.__DEV__ = NODE_ENV === 'development';
8+
global.__PROFILE__ = NODE_ENV === 'development';
89

910
global.requestAnimationFrame = function(callback) {
1011
setTimeout(callback);

scripts/rollup/build.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ const {
3939
UMD_PROD,
4040
NODE_DEV,
4141
NODE_PROD,
42+
NODE_PROFILING,
4243
FB_WWW_DEV,
4344
FB_WWW_PROD,
4445
RN_OSS_DEV,
4546
RN_OSS_PROD,
47+
RN_OSS_PROFILING,
4648
RN_FB_DEV,
4749
RN_FB_PROD,
4850
} = Bundles.bundleTypes;
@@ -95,6 +97,7 @@ function getBabelConfig(updateBabelOptions, bundleType, filename) {
9597
});
9698
case RN_OSS_DEV:
9799
case RN_OSS_PROD:
100+
case RN_OSS_PROFILING:
98101
case RN_FB_DEV:
99102
case RN_FB_PROD:
100103
return Object.assign({}, options, {
@@ -107,6 +110,7 @@ function getBabelConfig(updateBabelOptions, bundleType, filename) {
107110
case UMD_PROD:
108111
case NODE_DEV:
109112
case NODE_PROD:
113+
case NODE_PROFILING:
110114
return Object.assign({}, options, {
111115
plugins: options.plugins.concat([
112116
// Use object-assign polyfill in open source
@@ -152,10 +156,12 @@ function getFormat(bundleType) {
152156
return `umd`;
153157
case NODE_DEV:
154158
case NODE_PROD:
159+
case NODE_PROFILING:
155160
case FB_WWW_DEV:
156161
case FB_WWW_PROD:
157162
case RN_OSS_DEV:
158163
case RN_OSS_PROD:
164+
case RN_OSS_PROFILING:
159165
case RN_FB_DEV:
160166
case RN_FB_PROD:
161167
return `cjs`;
@@ -174,6 +180,8 @@ function getFilename(name, globalName, bundleType) {
174180
return `${name}.development.js`;
175181
case NODE_PROD:
176182
return `${name}.production.min.js`;
183+
case NODE_PROFILING:
184+
return `${name}.profiling.min.js`;
177185
case FB_WWW_DEV:
178186
case RN_OSS_DEV:
179187
case RN_FB_DEV:
@@ -182,6 +190,8 @@ function getFilename(name, globalName, bundleType) {
182190
case RN_OSS_PROD:
183191
case RN_FB_PROD:
184192
return `${globalName}-prod.js`;
193+
case RN_OSS_PROFILING:
194+
return `${globalName}-profiling.js`;
185195
}
186196
}
187197

@@ -195,15 +205,38 @@ function isProductionBundleType(bundleType) {
195205
return false;
196206
case UMD_PROD:
197207
case NODE_PROD:
208+
case NODE_PROFILING:
198209
case FB_WWW_PROD:
199210
case RN_OSS_PROD:
211+
case RN_OSS_PROFILING:
200212
case RN_FB_PROD:
201213
return true;
202214
default:
203215
throw new Error(`Unknown type: ${bundleType}`);
204216
}
205217
}
206218

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+
207240
function getPlugins(
208241
entry,
209242
externals,
@@ -218,11 +251,13 @@ function getPlugins(
218251
const findAndRecordErrorCodes = extractErrorCodes(errorCodeOpts);
219252
const forks = Modules.getForks(bundleType, entry, moduleType);
220253
const isProduction = isProductionBundleType(bundleType);
254+
const isProfiling = isProfilingBundleType(bundleType);
221255
const isInGlobalScope = bundleType === UMD_DEV || bundleType === UMD_PROD;
222256
const isFBBundle = bundleType === FB_WWW_DEV || bundleType === FB_WWW_PROD;
223257
const isRNBundle =
224258
bundleType === RN_OSS_DEV ||
225259
bundleType === RN_OSS_PROD ||
260+
bundleType === RN_OSS_PROFILING ||
226261
bundleType === RN_FB_DEV ||
227262
bundleType === RN_FB_PROD;
228263
const shouldStayReadable = isFBBundle || isRNBundle || forcePrettyOutput;
@@ -255,6 +290,7 @@ function getPlugins(
255290
// Turn __DEV__ and process.env checks into constants.
256291
replace({
257292
__DEV__: isProduction ? 'false' : 'true',
293+
__PROFILE__: isProfiling || !isProduction ? 'true' : 'false',
258294
'process.env.NODE_ENV': isProduction ? "'production'" : "'development'",
259295
}),
260296
// We still need CommonJS for external deps like object-assign.
@@ -508,10 +544,12 @@ async function buildEverything() {
508544
await createBundle(bundle, UMD_PROD);
509545
await createBundle(bundle, NODE_DEV);
510546
await createBundle(bundle, NODE_PROD);
547+
await createBundle(bundle, NODE_PROFILING);
511548
await createBundle(bundle, FB_WWW_DEV);
512549
await createBundle(bundle, FB_WWW_PROD);
513550
await createBundle(bundle, RN_OSS_DEV);
514551
await createBundle(bundle, RN_OSS_PROD);
552+
await createBundle(bundle, RN_OSS_PROFILING);
515553
await createBundle(bundle, RN_FB_DEV);
516554
await createBundle(bundle, RN_FB_PROD);
517555
}

scripts/rollup/bundles.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ const bundleTypes = {
55
UMD_PROD: 'UMD_PROD',
66
NODE_DEV: 'NODE_DEV',
77
NODE_PROD: 'NODE_PROD',
8+
NODE_PROFILING: 'NODE_PROFILING',
89
FB_WWW_DEV: 'FB_WWW_DEV',
910
FB_WWW_PROD: 'FB_WWW_PROD',
1011
RN_OSS_DEV: 'RN_OSS_DEV',
1112
RN_OSS_PROD: 'RN_OSS_PROD',
13+
RN_OSS_PROFILING: 'RN_OSS_PROFILING',
1214
RN_FB_DEV: 'RN_FB_DEV',
1315
RN_FB_PROD: 'RN_FB_PROD',
1416
};
@@ -17,10 +19,12 @@ const UMD_DEV = bundleTypes.UMD_DEV;
1719
const UMD_PROD = bundleTypes.UMD_PROD;
1820
const NODE_DEV = bundleTypes.NODE_DEV;
1921
const NODE_PROD = bundleTypes.NODE_PROD;
22+
const NODE_PROFILING = bundleTypes.NODE_PROFILING;
2023
const FB_WWW_DEV = bundleTypes.FB_WWW_DEV;
2124
const FB_WWW_PROD = bundleTypes.FB_WWW_PROD;
2225
const RN_OSS_DEV = bundleTypes.RN_OSS_DEV;
2326
const RN_OSS_PROD = bundleTypes.RN_OSS_PROD;
27+
const RN_OSS_PROFILING = bundleTypes.RN_OSS_PROFILING;
2428
const RN_FB_DEV = bundleTypes.RN_FB_DEV;
2529
const RN_FB_PROD = bundleTypes.RN_FB_PROD;
2630

@@ -69,6 +73,7 @@ const bundles = [
6973
UMD_PROD,
7074
NODE_DEV,
7175
NODE_PROD,
76+
NODE_PROFILING,
7277
FB_WWW_DEV,
7378
FB_WWW_PROD,
7479
],
@@ -175,7 +180,7 @@ const bundles = [
175180

176181
{
177182
label: 'native',
178-
bundleTypes: [RN_OSS_DEV, RN_OSS_PROD],
183+
bundleTypes: [RN_OSS_DEV, RN_OSS_PROD, RN_OSS_PROFILING],
179184
moduleType: RENDERER,
180185
entry: 'react-native-renderer',
181186
global: 'ReactNativeRenderer',
@@ -217,7 +222,7 @@ const bundles = [
217222

218223
{
219224
label: 'native-fabric',
220-
bundleTypes: [RN_OSS_DEV, RN_OSS_PROD],
225+
bundleTypes: [RN_OSS_DEV, RN_OSS_PROD, RN_OSS_PROFILING],
221226
moduleType: RENDERER,
222227
entry: 'react-native-renderer/fabric',
223228
global: 'ReactFabric',

scripts/rollup/forks.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const FB_WWW_DEV = bundleTypes.FB_WWW_DEV;
1010
const FB_WWW_PROD = bundleTypes.FB_WWW_PROD;
1111
const RN_OSS_DEV = bundleTypes.RN_OSS_DEV;
1212
const RN_OSS_PROD = bundleTypes.RN_OSS_PROD;
13+
const RN_OSS_PROFILING = bundleTypes.RN_OSS_PROFILING;
1314
const RN_FB_DEV = bundleTypes.RN_FB_DEV;
1415
const RN_FB_PROD = bundleTypes.RN_FB_PROD;
1516
const RENDERER = moduleTypes.RENDERER;
@@ -45,6 +46,7 @@ const forks = Object.freeze({
4546
return 'shared/forks/ReactFeatureFlags.native-fb.js';
4647
case RN_OSS_DEV:
4748
case RN_OSS_PROD:
49+
case RN_OSS_PROFILING:
4850
return 'shared/forks/ReactFeatureFlags.native-oss.js';
4951
default:
5052
throw Error(
@@ -58,6 +60,7 @@ const forks = Object.freeze({
5860
return 'shared/forks/ReactFeatureFlags.native-fabric-fb.js';
5961
case RN_OSS_DEV:
6062
case RN_OSS_PROD:
63+
case RN_OSS_PROFILING:
6164
return 'shared/forks/ReactFeatureFlags.native-fabric-oss.js';
6265
default:
6366
throw Error(
@@ -143,6 +146,7 @@ const forks = Object.freeze({
143146
return 'react-reconciler/src/forks/ReactFiberErrorDialog.www.js';
144147
case RN_OSS_DEV:
145148
case RN_OSS_PROD:
149+
case RN_OSS_PROFILING:
146150
case RN_FB_DEV:
147151
case RN_FB_PROD:
148152
switch (entry) {

scripts/rollup/packaging.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ const {
1414
UMD_PROD,
1515
NODE_DEV,
1616
NODE_PROD,
17+
NODE_PROFILING,
1718
FB_WWW_DEV,
1819
FB_WWW_PROD,
1920
RN_OSS_DEV,
2021
RN_OSS_PROD,
22+
RN_OSS_PROFILING,
2123
RN_FB_DEV,
2224
RN_FB_PROD,
2325
} = Bundles.bundleTypes;
@@ -33,6 +35,7 @@ function getBundleOutputPaths(bundleType, filename, packageName) {
3335
switch (bundleType) {
3436
case NODE_DEV:
3537
case NODE_PROD:
38+
case NODE_PROFILING:
3639
return [`build/node_modules/${packageName}/cjs/${filename}`];
3740
case UMD_DEV:
3841
case UMD_PROD:
@@ -45,6 +48,7 @@ function getBundleOutputPaths(bundleType, filename, packageName) {
4548
return [`build/facebook-www/${filename}`];
4649
case RN_OSS_DEV:
4750
case RN_OSS_PROD:
51+
case RN_OSS_PROFILING:
4852
switch (packageName) {
4953
case 'react-native-renderer':
5054
return [`build/react-native/oss/${filename}`];

0 commit comments

Comments
 (0)