Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] New ReactDefaultPerf #962

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions examples/todomvc-director/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
<div id="benchmark"></div>

<script src="bower_components/todomvc-common/base.js"></script>
<script src="bower_components/react/react.js"></script>
<script src="bower_components/react/JSXTransformer.js"></script>
<script src="../../build/react-with-addons.js"></script>
<script src="../../build/JSXTransformer.js"></script>
<script src="bower_components/director/build/director.min.js"></script>


<script type="text/jsx" src="js/utils.jsx"></script>
<script type="text/jsx" src="js/todoItem.jsx"></script>
<script type="text/jsx" src="js/footer.jsx"></script>
Expand Down
4 changes: 4 additions & 0 deletions src/ReactWithAddons.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,9 @@ React.addons = {
TransitionGroup: ReactTransitionGroup
};

if (__DEV__) {
React.addons.Perf = require('ReactDefaultPerf');
}

module.exports = React;

46 changes: 25 additions & 21 deletions src/core/ReactCompositeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -1150,28 +1150,32 @@ var ReactCompositeComponentMixin = {
/**
* @private
*/
_renderValidatedComponent: function() {
var renderedComponent;
var previousContext = ReactContext.current;
ReactContext.current = this._processChildContext(this._currentContext);
ReactCurrentOwner.current = this;
try {
renderedComponent = this.render();
} catch (error) {
// IE8 requires `catch` in order to use `finally`.
throw error;
} finally {
ReactContext.current = previousContext;
ReactCurrentOwner.current = null;
_renderValidatedComponent: ReactPerf.measure(
'ReactCompositeComponent',
'_renderValidatedComponent',
function() {
var renderedComponent;
var previousContext = ReactContext.current;
ReactContext.current = this._processChildContext(this._currentContext);
ReactCurrentOwner.current = this;
try {
renderedComponent = this.render();
} catch (error) {
// IE8 requires `catch` in order to use `finally`.
throw error;
} finally {
ReactContext.current = previousContext;
ReactCurrentOwner.current = null;
}
invariant(
ReactComponent.isValidComponent(renderedComponent),
'%s.render(): A valid ReactComponent must be returned. You may have ' +
'returned null, undefined, an array, or some other invalid object.',
this.constructor.displayName || 'ReactCompositeComponent'
);
return renderedComponent;
}
invariant(
ReactComponent.isValidComponent(renderedComponent),
'%s.render(): A valid ReactComponent must be returned. You may have ' +
'returned null, undefined, an array, or some other invalid object.',
this.constructor.displayName || 'ReactCompositeComponent'
);
return renderedComponent;
},
),

/**
* @private
Expand Down
37 changes: 19 additions & 18 deletions src/core/ReactDOMIDOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var CSSPropertyOperations = require('CSSPropertyOperations');
var DOMChildrenOperations = require('DOMChildrenOperations');
var DOMPropertyOperations = require('DOMPropertyOperations');
var ReactMount = require('ReactMount');
var ReactPerf = require('ReactPerf');

var getTextContentAccessor = require('getTextContentAccessor');
var invariant = require('invariant');
Expand Down Expand Up @@ -66,7 +67,7 @@ var ReactDOMIDOperations = {
* @param {*} value New value of the property.
* @internal
*/
updatePropertyByID: function(id, name, value) {
updatePropertyByID: ReactPerf.measure('ReactDOMIDOperations', 'updatePropertyByID', function(id, name, value) {
var node = ReactMount.getNode(id);
invariant(
!INVALID_PROPERTY_ERRORS.hasOwnProperty(name),
Expand All @@ -82,7 +83,7 @@ var ReactDOMIDOperations = {
} else {
DOMPropertyOperations.deleteValueForProperty(node, name);
}
},
}),

/**
* Updates a DOM node to remove a property. This should only be used to remove
Expand All @@ -92,15 +93,15 @@ var ReactDOMIDOperations = {
* @param {string} name A property name to remove, see `DOMProperty`.
* @internal
*/
deletePropertyByID: function(id, name, value) {
deletePropertyByID: ReactPerf.measure('ReactDOMIDOperations', 'deletePropertyByID', function(id, name, value) {
var node = ReactMount.getNode(id);
invariant(
!INVALID_PROPERTY_ERRORS.hasOwnProperty(name),
'updatePropertyByID(...): %s',
INVALID_PROPERTY_ERRORS[name]
);
DOMPropertyOperations.deleteValueForProperty(node, name, value);
},
}),

/**
* Updates a DOM node with new style values. If a value is specified as '',
Expand All @@ -110,10 +111,10 @@ var ReactDOMIDOperations = {
* @param {object} styles Mapping from styles to values.
* @internal
*/
updateStylesByID: function(id, styles) {
updateStylesByID: ReactPerf.measure('ReactDOMIDOperations', 'updateStylesByID', function(id, styles) {
var node = ReactMount.getNode(id);
CSSPropertyOperations.setValueForStyles(node, styles);
},
}),

/**
* Updates a DOM node's innerHTML.
Expand All @@ -122,29 +123,29 @@ var ReactDOMIDOperations = {
* @param {string} html An HTML string.
* @internal
*/
updateInnerHTMLByID: function(id, html) {
updateInnerHTMLByID: ReactPerf.measure('ReactDOMIDOperations', 'updateInnerHTMLByID', function(id, html) {
var node = ReactMount.getNode(id);

// IE8: When updating a just created node with innerHTML only leading
// whitespace is removed. When updating an existing node with innerHTML
// whitespace in root TextNodes is also collapsed.
// @see quirksmode.org/bugreports/archives/2004/11/innerhtml_and_t.html

if (useWhitespaceWorkaround === undefined) {
// Feature detection; only IE8 is known to behave improperly like this.
var temp = document.createElement('div');
temp.innerHTML = ' ';
useWhitespaceWorkaround = temp.innerHTML === '';
}

if (useWhitespaceWorkaround) {
// Magic theory: IE8 supposedly differentiates between added and updated
// nodes when processing innerHTML, innerHTML on updated nodes suffers
// from worse whitespace behavior. Re-adding a node like this triggers
// the initial and more favorable whitespace behavior.
node.parentNode.replaceChild(node, node);
}

if (useWhitespaceWorkaround && html.match(/^[ \r\n\t\f]/)) {
// Recover leading whitespace by temporarily prepending any character.
// \uFEFF has the potential advantage of being zero-width/invisible.
Expand All @@ -153,7 +154,7 @@ var ReactDOMIDOperations = {
} else {
node.innerHTML = html;
}
},
}),

/**
* Updates a DOM node's text content set by `props.content`.
Expand All @@ -162,10 +163,10 @@ var ReactDOMIDOperations = {
* @param {string} content Text content.
* @internal
*/
updateTextContentByID: function(id, content) {
updateTextContentByID: ReactPerf.measure('ReactDOMIDOperations', 'updateTextContentByID', function(id, content) {
var node = ReactMount.getNode(id);
node[textContentAccessor] = content;
},
}),

/**
* Replaces a DOM node that exists in the document with markup.
Expand All @@ -175,10 +176,10 @@ var ReactDOMIDOperations = {
* @internal
* @see {Danger.dangerouslyReplaceNodeWithMarkup}
*/
dangerouslyReplaceNodeWithMarkupByID: function(id, markup) {
dangerouslyReplaceNodeWithMarkupByID: ReactPerf.measure('ReactDOMIDOperations', 'dangerouslyReplaceNodeWithMarkupByID', function(id, markup) {
var node = ReactMount.getNode(id);
DOMChildrenOperations.dangerouslyReplaceNodeWithMarkup(node, markup);
},
}),

/**
* Updates a component's children by processing a series of updates.
Expand All @@ -187,12 +188,12 @@ var ReactDOMIDOperations = {
* @param {array<string>} markup List of markup strings.
* @internal
*/
dangerouslyProcessChildrenUpdates: function(updates, markup) {
dangerouslyProcessChildrenUpdates: ReactPerf.measure('ReactDOMIDOperations', 'dangerouslyProcessChildrenUpdates', function(updates, markup) {
for (var i = 0; i < updates.length; i++) {
updates[i].parentNode = ReactMount.getNode(updates[i].parentID);
}
DOMChildrenOperations.processUpdates(updates, markup);
}
})

};

Expand Down
4 changes: 0 additions & 4 deletions src/core/ReactDefaultInjection.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ function inject() {

DOMProperty.injection.injectDOMPropertyConfig(DefaultDOMPropertyConfig);

if (__DEV__) {
ReactPerf.injection.injectMeasure(require('ReactDefaultPerf').measure);
}

ReactUpdates.injection.injectBatchingStrategy(
ReactDefaultBatchingStrategy
);
Expand Down
6 changes: 4 additions & 2 deletions src/core/ReactUpdates.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

"use strict";

var ReactPerf = require('ReactPerf');

var invariant = require('invariant');

var dirtyComponents = [];
Expand Down Expand Up @@ -75,7 +77,7 @@ function clearDirtyComponents() {
dirtyComponents.length = 0;
}

function flushBatchedUpdates() {
var flushBatchedUpdates = ReactPerf.measure('ReactUpdates', 'flushBatchedUpdates', function() {
// Run these in separate functions so the JIT can optimize
try {
runBatchedUpdates();
Expand All @@ -85,7 +87,7 @@ function flushBatchedUpdates() {
} finally {
clearDirtyComponents();
}
}
});

/**
* Mark a component as needing a rerender, adding an optional callback to a
Expand Down
Loading