@samitouri / QOS-React-2 / commits / 20af6a7ce8

Speed Owner Access (by over 9000)

Use a valid identifier (and non-string) to reduce chance of de-optimizing in V8 and Nitro.

Tim Yung committed Oct 1, 2013 at 16:28 UTC 20af6a7ce880046b273a93afc53ff474e7693af5
2 files changed +13 -17
src/core/ReactComponent.js
+12 -16
@@ -27,12 +27,6 @@ var invariant = require('invariant');
27 var keyMirror = require('keyMirror');
28 var merge = require('merge');
29
30 -/**
31 - * Prop key that references a component's owner.
32 - * @private
33 - */
34 -var OWNER = '{owner}';
35 -
30 /**
31 * Props key that determines if a component's key was already validated.
32 * @private
@@ -93,7 +87,8 @@ function validateExplicitKey(component) {
87 if (!component.isOwnedBy(ReactCurrentOwner.current)) {
88 // Name of the component that originally created this child.
89 var childOwnerName =
96 - component.props[OWNER] && component.props[OWNER].constructor.displayName;
90 + component.props.__owner__ &&
91 + component.props.__owner__.constructor.displayName;
92
93 // Usually the current owner is the offender, but if it accepts
94 // children as a property, it may be the creator of the child that's
@@ -271,7 +266,7 @@ var ReactComponent = {
266 */
267 replaceProps: function(props, callback) {
268 invariant(
274 - !this.props[OWNER],
269 + !this.props.__owner__,
270 'replaceProps(...): You called `setProps` or `replaceProps` on a ' +
271 'component with an owner. This is an anti-pattern since props will ' +
272 'get reactively updated when rendered. Instead, change the owner\'s ' +
@@ -299,7 +294,7 @@ var ReactComponent = {
294 construct: function(initialProps, children) {
295 this.props = initialProps || {};
296 // Record the component responsible for creating this component.
302 - this.props[OWNER] = ReactCurrentOwner.current;
297 + this.props.__owner__ = ReactCurrentOwner.current;
298 // All components start unmounted.
299 this._lifeCycleState = ComponentLifeCycle.UNMOUNTED;
300
@@ -347,7 +342,7 @@ var ReactComponent = {
342 );
343 var props = this.props;
344 if (props.ref != null) {
350 - ReactOwner.addComponentAsRefTo(this, props.ref, props[OWNER]);
345 + ReactOwner.addComponentAsRefTo(this, props.ref, props.__owner__);
346 }
347 this._rootNodeID = rootID;
348 this._lifeCycleState = ComponentLifeCycle.MOUNTED;
@@ -372,7 +367,7 @@ var ReactComponent = {
367 );
368 var props = this.props;
369 if (props.ref != null) {
375 - ReactOwner.removeComponentAsRefFrom(this, props.ref, props[OWNER]);
370 + ReactOwner.removeComponentAsRefFrom(this, props.ref, props.__owner__);
371 }
372 ReactComponent.unmountIDFromEnvironment(this._rootNodeID);
373 this._rootNodeID = null;
@@ -438,15 +433,16 @@ var ReactComponent = {
433 // If either the owner or a `ref` has changed, make sure the newest owner
434 // has stored a reference to `this`, and the previous owner (if different)
435 // has forgotten the reference to `this`.
441 - if (props[OWNER] !== prevProps[OWNER] || props.ref !== prevProps.ref) {
436 + if (props.__owner__ !== prevProps.__owner__ ||
437 + props.ref !== prevProps.ref) {
438 if (prevProps.ref != null) {
439 ReactOwner.removeComponentAsRefFrom(
444 - this, prevProps.ref, prevProps[OWNER]
440 + this, prevProps.ref, prevProps.__owner__
441 );
442 }
443 // Correct, even if the owner is the same, and only the ref has changed.
444 if (props.ref != null) {
449 - ReactOwner.addComponentAsRefTo(this, props.ref, props[OWNER]);
445 + ReactOwner.addComponentAsRefTo(this, props.ref, props.__owner__);
446 }
447 }
448 },
@@ -500,7 +496,7 @@ var ReactComponent = {
496 * @internal
497 */
498 isOwnedBy: function(owner) {
503 - return this.props[OWNER] === owner;
499 + return this.props.__owner__ === owner;
500 },
501
502 /**
@@ -512,7 +508,7 @@ var ReactComponent = {
508 * @internal
509 */
510 getSiblingByRef: function(ref) {
515 - var owner = this.props[OWNER];
511 + var owner = this.props.__owner__;
512 if (!owner || !owner.refs) {
513 return null;
514 }
src/dom/DOMPropertyOperations.js
+1 -1
@@ -30,7 +30,7 @@ var processAttributeNameAndPrefix = memoizeStringOnly(function(name) {
30
31 if (__DEV__) {
32 var reactProps = {
33 - '{owner}': true,
33 + __owner__: true,
34 children: true,
35 dangerouslySetInnerHTML: true,
36 key: true,