Skip to content

Commit

Permalink
Added production profiling bundle type (#12886)
Browse files Browse the repository at this point in the history
* Added profiling bundle
* Turned profiling on for React Fabric OSS profiling and dev bundles
* Added new global var "__PROFILE__" for profiling DCE
  • Loading branch information
bvaughn authored Jun 11, 2018
1 parent ec60457 commit d5c1119
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 5 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,6 @@ module.exports = {
spyOnDev: true,
spyOnDevAndProd: true,
spyOnProd: true,
__PROFILE__: true,
},
};
2 changes: 1 addition & 1 deletion packages/shared/ReactFeatureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const warnAboutDeprecatedLifecycles = false;
export const warnAboutLegacyContextAPI = false;

// Gather advanced timing metrics for Profiler subtrees.
export const enableProfilerTimer = __DEV__;
export const enableProfilerTimer = __PROFILE__;

// Fires getDerivedStateFromProps for state *or* props changes
export const fireGetDerivedStateFromPropsOnStateUpdates = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const enableSuspense = false;
export const warnAboutDeprecatedLifecycles = false;
export const warnAboutLegacyContextAPI = false;
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
export const enableProfilerTimer = false;
export const enableProfilerTimer = __PROFILE__;
export const fireGetDerivedStateFromPropsOnStateUpdates = true;

// Only used in www builds.
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/forks/ReactFeatureFlags.native-oss.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const enableUserTimingAPI = __DEV__;
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
export const warnAboutDeprecatedLifecycles = false;
export const warnAboutLegacyContextAPI = false;
export const enableProfilerTimer = __DEV__;
export const enableProfilerTimer = __PROFILE__;
export const fireGetDerivedStateFromPropsOnStateUpdates = true;

// Only used in www builds.
Expand Down
2 changes: 2 additions & 0 deletions scripts/flow/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

/* eslint-disable */

declare var __PROFILE__: boolean;

declare var __REACT_DEVTOOLS_GLOBAL_HOOK__: any; /*?{
inject: ?((stuff: Object) => void)
};*/
Expand Down
1 change: 1 addition & 0 deletions scripts/jest/setupEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ if (NODE_ENV !== 'development' && NODE_ENV !== 'production') {
throw new Error('NODE_ENV must either be set to development or production.');
}
global.__DEV__ = NODE_ENV === 'development';
global.__PROFILE__ = NODE_ENV === 'development';

global.requestAnimationFrame = function(callback) {
setTimeout(callback);
Expand Down
38 changes: 38 additions & 0 deletions scripts/rollup/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ const {
UMD_PROD,
NODE_DEV,
NODE_PROD,
NODE_PROFILING,
FB_WWW_DEV,
FB_WWW_PROD,
RN_OSS_DEV,
RN_OSS_PROD,
RN_OSS_PROFILING,
RN_FB_DEV,
RN_FB_PROD,
} = Bundles.bundleTypes;
Expand Down Expand Up @@ -95,6 +97,7 @@ function getBabelConfig(updateBabelOptions, bundleType, filename) {
});
case RN_OSS_DEV:
case RN_OSS_PROD:
case RN_OSS_PROFILING:
case RN_FB_DEV:
case RN_FB_PROD:
return Object.assign({}, options, {
Expand All @@ -107,6 +110,7 @@ function getBabelConfig(updateBabelOptions, bundleType, filename) {
case UMD_PROD:
case NODE_DEV:
case NODE_PROD:
case NODE_PROFILING:
return Object.assign({}, options, {
plugins: options.plugins.concat([
// Use object-assign polyfill in open source
Expand Down Expand Up @@ -152,10 +156,12 @@ function getFormat(bundleType) {
return `umd`;
case NODE_DEV:
case NODE_PROD:
case NODE_PROFILING:
case FB_WWW_DEV:
case FB_WWW_PROD:
case RN_OSS_DEV:
case RN_OSS_PROD:
case RN_OSS_PROFILING:
case RN_FB_DEV:
case RN_FB_PROD:
return `cjs`;
Expand All @@ -174,6 +180,8 @@ function getFilename(name, globalName, bundleType) {
return `${name}.development.js`;
case NODE_PROD:
return `${name}.production.min.js`;
case NODE_PROFILING:
return `${name}.profiling.min.js`;
case FB_WWW_DEV:
case RN_OSS_DEV:
case RN_FB_DEV:
Expand All @@ -182,6 +190,8 @@ function getFilename(name, globalName, bundleType) {
case RN_OSS_PROD:
case RN_FB_PROD:
return `${globalName}-prod.js`;
case RN_OSS_PROFILING:
return `${globalName}-profiling.js`;
}
}

Expand All @@ -195,15 +205,38 @@ function isProductionBundleType(bundleType) {
return false;
case UMD_PROD:
case NODE_PROD:
case NODE_PROFILING:
case FB_WWW_PROD:
case RN_OSS_PROD:
case RN_OSS_PROFILING:
case RN_FB_PROD:
return true;
default:
throw new Error(`Unknown type: ${bundleType}`);
}
}

function isProfilingBundleType(bundleType) {
switch (bundleType) {
case FB_WWW_DEV:
case FB_WWW_PROD:
case NODE_DEV:
case NODE_PROD:
case RN_FB_DEV:
case RN_FB_PROD:
case RN_OSS_DEV:
case RN_OSS_PROD:
case UMD_DEV:
case UMD_PROD:
return false;
case NODE_PROFILING:
case RN_OSS_PROFILING:
return true;
default:
throw new Error(`Unknown type: ${bundleType}`);
}
}

function getPlugins(
entry,
externals,
Expand All @@ -218,11 +251,13 @@ function getPlugins(
const findAndRecordErrorCodes = extractErrorCodes(errorCodeOpts);
const forks = Modules.getForks(bundleType, entry, moduleType);
const isProduction = isProductionBundleType(bundleType);
const isProfiling = isProfilingBundleType(bundleType);
const isInGlobalScope = bundleType === UMD_DEV || bundleType === UMD_PROD;
const isFBBundle = bundleType === FB_WWW_DEV || bundleType === FB_WWW_PROD;
const isRNBundle =
bundleType === RN_OSS_DEV ||
bundleType === RN_OSS_PROD ||
bundleType === RN_OSS_PROFILING ||
bundleType === RN_FB_DEV ||
bundleType === RN_FB_PROD;
const shouldStayReadable = isFBBundle || isRNBundle || forcePrettyOutput;
Expand Down Expand Up @@ -255,6 +290,7 @@ function getPlugins(
// Turn __DEV__ and process.env checks into constants.
replace({
__DEV__: isProduction ? 'false' : 'true',
__PROFILE__: isProfiling || !isProduction ? 'true' : 'false',
'process.env.NODE_ENV': isProduction ? "'production'" : "'development'",
}),
// We still need CommonJS for external deps like object-assign.
Expand Down Expand Up @@ -508,10 +544,12 @@ async function buildEverything() {
await createBundle(bundle, UMD_PROD);
await createBundle(bundle, NODE_DEV);
await createBundle(bundle, NODE_PROD);
await createBundle(bundle, NODE_PROFILING);
await createBundle(bundle, FB_WWW_DEV);
await createBundle(bundle, FB_WWW_PROD);
await createBundle(bundle, RN_OSS_DEV);
await createBundle(bundle, RN_OSS_PROD);
await createBundle(bundle, RN_OSS_PROFILING);
await createBundle(bundle, RN_FB_DEV);
await createBundle(bundle, RN_FB_PROD);
}
Expand Down
9 changes: 7 additions & 2 deletions scripts/rollup/bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ const bundleTypes = {
UMD_PROD: 'UMD_PROD',
NODE_DEV: 'NODE_DEV',
NODE_PROD: 'NODE_PROD',
NODE_PROFILING: 'NODE_PROFILING',
FB_WWW_DEV: 'FB_WWW_DEV',
FB_WWW_PROD: 'FB_WWW_PROD',
RN_OSS_DEV: 'RN_OSS_DEV',
RN_OSS_PROD: 'RN_OSS_PROD',
RN_OSS_PROFILING: 'RN_OSS_PROFILING',
RN_FB_DEV: 'RN_FB_DEV',
RN_FB_PROD: 'RN_FB_PROD',
};
Expand All @@ -17,10 +19,12 @@ const UMD_DEV = bundleTypes.UMD_DEV;
const UMD_PROD = bundleTypes.UMD_PROD;
const NODE_DEV = bundleTypes.NODE_DEV;
const NODE_PROD = bundleTypes.NODE_PROD;
const NODE_PROFILING = bundleTypes.NODE_PROFILING;
const FB_WWW_DEV = bundleTypes.FB_WWW_DEV;
const FB_WWW_PROD = bundleTypes.FB_WWW_PROD;
const RN_OSS_DEV = bundleTypes.RN_OSS_DEV;
const RN_OSS_PROD = bundleTypes.RN_OSS_PROD;
const RN_OSS_PROFILING = bundleTypes.RN_OSS_PROFILING;
const RN_FB_DEV = bundleTypes.RN_FB_DEV;
const RN_FB_PROD = bundleTypes.RN_FB_PROD;

Expand Down Expand Up @@ -69,6 +73,7 @@ const bundles = [
UMD_PROD,
NODE_DEV,
NODE_PROD,
NODE_PROFILING,
FB_WWW_DEV,
FB_WWW_PROD,
],
Expand Down Expand Up @@ -175,7 +180,7 @@ const bundles = [

{
label: 'native',
bundleTypes: [RN_OSS_DEV, RN_OSS_PROD],
bundleTypes: [RN_OSS_DEV, RN_OSS_PROD, RN_OSS_PROFILING],
moduleType: RENDERER,
entry: 'react-native-renderer',
global: 'ReactNativeRenderer',
Expand Down Expand Up @@ -217,7 +222,7 @@ const bundles = [

{
label: 'native-fabric',
bundleTypes: [RN_OSS_DEV, RN_OSS_PROD],
bundleTypes: [RN_OSS_DEV, RN_OSS_PROD, RN_OSS_PROFILING],
moduleType: RENDERER,
entry: 'react-native-renderer/fabric',
global: 'ReactFabric',
Expand Down
4 changes: 4 additions & 0 deletions scripts/rollup/forks.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const FB_WWW_DEV = bundleTypes.FB_WWW_DEV;
const FB_WWW_PROD = bundleTypes.FB_WWW_PROD;
const RN_OSS_DEV = bundleTypes.RN_OSS_DEV;
const RN_OSS_PROD = bundleTypes.RN_OSS_PROD;
const RN_OSS_PROFILING = bundleTypes.RN_OSS_PROFILING;
const RN_FB_DEV = bundleTypes.RN_FB_DEV;
const RN_FB_PROD = bundleTypes.RN_FB_PROD;
const RENDERER = moduleTypes.RENDERER;
Expand Down Expand Up @@ -45,6 +46,7 @@ const forks = Object.freeze({
return 'shared/forks/ReactFeatureFlags.native-fb.js';
case RN_OSS_DEV:
case RN_OSS_PROD:
case RN_OSS_PROFILING:
return 'shared/forks/ReactFeatureFlags.native-oss.js';
default:
throw Error(
Expand All @@ -58,6 +60,7 @@ const forks = Object.freeze({
return 'shared/forks/ReactFeatureFlags.native-fabric-fb.js';
case RN_OSS_DEV:
case RN_OSS_PROD:
case RN_OSS_PROFILING:
return 'shared/forks/ReactFeatureFlags.native-fabric-oss.js';
default:
throw Error(
Expand Down Expand Up @@ -143,6 +146,7 @@ const forks = Object.freeze({
return 'react-reconciler/src/forks/ReactFiberErrorDialog.www.js';
case RN_OSS_DEV:
case RN_OSS_PROD:
case RN_OSS_PROFILING:
case RN_FB_DEV:
case RN_FB_PROD:
switch (entry) {
Expand Down
4 changes: 4 additions & 0 deletions scripts/rollup/packaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ const {
UMD_PROD,
NODE_DEV,
NODE_PROD,
NODE_PROFILING,
FB_WWW_DEV,
FB_WWW_PROD,
RN_OSS_DEV,
RN_OSS_PROD,
RN_OSS_PROFILING,
RN_FB_DEV,
RN_FB_PROD,
} = Bundles.bundleTypes;
Expand All @@ -33,6 +35,7 @@ function getBundleOutputPaths(bundleType, filename, packageName) {
switch (bundleType) {
case NODE_DEV:
case NODE_PROD:
case NODE_PROFILING:
return [`build/node_modules/${packageName}/cjs/${filename}`];
case UMD_DEV:
case UMD_PROD:
Expand All @@ -45,6 +48,7 @@ function getBundleOutputPaths(bundleType, filename, packageName) {
return [`build/facebook-www/${filename}`];
case RN_OSS_DEV:
case RN_OSS_PROD:
case RN_OSS_PROFILING:
switch (packageName) {
case 'react-native-renderer':
return [`build/react-native/oss/${filename}`];
Expand Down
35 changes: 35 additions & 0 deletions scripts/rollup/wrappers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ const UMD_DEV = Bundles.bundleTypes.UMD_DEV;
const UMD_PROD = Bundles.bundleTypes.UMD_PROD;
const NODE_DEV = Bundles.bundleTypes.NODE_DEV;
const NODE_PROD = Bundles.bundleTypes.NODE_PROD;
const NODE_PROFILING = Bundles.bundleTypes.NODE_PROFILING;
const FB_WWW_DEV = Bundles.bundleTypes.FB_WWW_DEV;
const FB_WWW_PROD = Bundles.bundleTypes.FB_WWW_PROD;
const RN_OSS_DEV = Bundles.bundleTypes.RN_OSS_DEV;
const RN_OSS_PROD = Bundles.bundleTypes.RN_OSS_PROD;
const RN_OSS_PROFILING = Bundles.bundleTypes.RN_OSS_PROFILING;
const RN_FB_DEV = Bundles.bundleTypes.RN_FB_DEV;
const RN_FB_PROD = Bundles.bundleTypes.RN_FB_PROD;

Expand Down Expand Up @@ -91,6 +93,25 @@ ${
${source}`;
},

/***************** NODE_PROFILING *****************/
[NODE_PROFILING](source, globalName, filename, moduleType) {
return `/** @license React v${reactVersion}
* ${filename}
*
${license}
*/
${
globalName === 'ReactNoopRenderer' ||
globalName === 'ReactNoopRendererPersistent'
? // React Noop needs regenerator runtime because it uses
// generators but GCC doesn't handle them in the output.
// So we use Babel for them.
`const regeneratorRuntime = require("regenerator-runtime");`
: ``
}
${source}`;
},

/****************** FB_WWW_DEV ******************/
[FB_WWW_DEV](source, globalName, filename, moduleType) {
return `/**
Expand Down Expand Up @@ -154,6 +175,20 @@ ${license}
* ${'@gen' + 'erated'}
*/
${source}`;
},

/****************** RN_OSS_PROFILING ******************/
[RN_OSS_PROFILING](source, globalName, filename, moduleType) {
return `/**
${license}
*
* @noflow
* @providesModule ${globalName}-profiling
* @preventMunge
* ${'@gen' + 'erated'}
*/
${source}`;
},

Expand Down

0 comments on commit d5c1119

Please sign in to comment.