mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[perf] Change how ReactDefaultPerf is injected
ReactDefaultPerf should inject itself when require()'d. This continues to support the ?react_perf use case for logging on initial page load.
This commit is contained in:
committed by
Paul O’Shannessy
parent
12ebf33f89
commit
a6749a686f
@@ -91,10 +91,6 @@ function inject() {
|
||||
|
||||
ReactInjection.DOMProperty.injectDOMPropertyConfig(DefaultDOMPropertyConfig);
|
||||
|
||||
if (__DEV__) {
|
||||
ReactInjection.Perf.injectMeasure(require('ReactDefaultPerf').measure);
|
||||
}
|
||||
|
||||
ReactInjection.Updates.injectBatchingStrategy(
|
||||
ReactDefaultBatchingStrategy
|
||||
);
|
||||
@@ -104,6 +100,14 @@ function inject() {
|
||||
ClientReactRootIndex.createReactRootIndex :
|
||||
ServerReactRootIndex.createReactRootIndex
|
||||
);
|
||||
|
||||
if (__DEV__) {
|
||||
var url = (ExecutionEnvironment.canUseDOM && window.location.href) || '';
|
||||
if ((/[?&]react_perf\b/).test(url)) {
|
||||
var ReactDefaultPerf = require('ReactDefaultPerf');
|
||||
ReactDefaultPerf.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -19,12 +19,27 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
var ReactPerf = require('ReactPerf');
|
||||
|
||||
var performanceNow = require('performanceNow');
|
||||
|
||||
var ReactDefaultPerf = {};
|
||||
|
||||
if (__DEV__) {
|
||||
ReactDefaultPerf = {
|
||||
_injected: false,
|
||||
|
||||
start: function() {
|
||||
if (!ReactDefaultPerf._injected) {
|
||||
ReactPerf.injection.injectMeasure(ReactDefaultPerf.measure);
|
||||
}
|
||||
ReactPerf.enableMeasure = true;
|
||||
},
|
||||
|
||||
stop: function() {
|
||||
ReactPerf.enableMeasure = false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets the stored information for a given object's function.
|
||||
*
|
||||
@@ -293,7 +308,7 @@ if (__DEV__) {
|
||||
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
|
||||
var fnStr = fn.toString().replace(STRIP_COMMENTS, '');
|
||||
fnStr = fnStr.slice(fnStr.indexOf('(') + 1, fnStr.indexOf(')'));
|
||||
return fnStr.match(/([^\s,]+)/g);
|
||||
return fnStr.match(/([^\s,]+)/g) || [];
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,6 +19,10 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* ReactPerf is a general AOP system designed to measure performance. This
|
||||
* module only has the hooks: see ReactDefaultPerf for the analysis tool.
|
||||
*/
|
||||
var ReactPerf = {
|
||||
/**
|
||||
* Boolean to enable/disable measurement. Set to false by default to prevent
|
||||
@@ -33,7 +37,7 @@ var ReactPerf = {
|
||||
storedMeasure: _noMeasure,
|
||||
|
||||
/**
|
||||
* Use this to wrap methods you want to measure.
|
||||
* Use this to wrap methods you want to measure. Zero overhead in production.
|
||||
*
|
||||
* @param {string} objName
|
||||
* @param {string} fnName
|
||||
@@ -66,13 +70,6 @@ var ReactPerf = {
|
||||
}
|
||||
};
|
||||
|
||||
if (__DEV__) {
|
||||
var ExecutionEnvironment = require('ExecutionEnvironment');
|
||||
var url = (ExecutionEnvironment.canUseDOM && window.location.href) || '';
|
||||
ReactPerf.enableMeasure = ReactPerf.enableMeasure ||
|
||||
(/[?&]react_perf\b/).test(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simply passes through the measured function, without measuring it.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user