-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Consolidate hook events #7472
Consolidate hook events #7472
Conversation
It is unnecessary. We now pass the element as part of onInstantiateComponent, and it can't change before mounting.
It is unused after #7410.
We already have onBeforeUpdateComponent. Let's just have on(Before?)(Mount|Update|Unmount)Component and stick with them. This removes double event dispatches in some hot spots.
The tests still pass so presumably it was not necessary.
Does this change ReactPerf output at all? |
No, this shouldn’t affect it. |
This lets us further consolidate hooks. The parent ID is now passed as an argument to onBeforeMountComponent() with the element.
); | ||
return nextChildren; | ||
} | ||
} | ||
nextChildren = flattenChildren(nextNestedChildrenElements); | ||
nextChildren = flattenChildren(nextNestedChildrenElements, selfDebugID); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting that we weren’t passing it before (this code path could still run in __DEV__
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, when is this._currentElement not set? Not even sure why we have that check.
@@ -109,12 +109,17 @@ function mountComponentIntoNode( | |||
console.time(markerName); | |||
} | |||
|
|||
var parentDebugID; | |||
if (__DEV__) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we drop these __DEV__
blocks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea.
It is unnecessary now that we pass the parent ID to onBeforeMountComponent.
This removes some awkward branching.
* Remove onBeforeMountComponent hook event It is unnecessary. We now pass the element as part of onInstantiateComponent, and it can't change before mounting. * Remove onComponentHasMounted hook event It is unused after #7410. * Replace on(Begin|End)ReconcilerTimer hook events We already have onBeforeUpdateComponent. Let's just have on(Before?)(Mount|Update|Unmount)Component and stick with them. This removes double event dispatches in some hot spots. * Remove onComponentHasUpdated hook The tests still pass so presumably it was not necessary. * Add missing __DEV__ to TestUtils code * Replace on(InstantiateComponent|SetParent) with onBeforeMountComponent This lets us further consolidate hooks. The parent ID is now passed as an argument to onBeforeMountComponent() with the element. * Remove onMountRootComponent hook event It is unnecessary now that we pass the parent ID to onBeforeMountComponent. * Use parentDebugID = 0 both for roots and production This removes some awkward branching. (cherry picked from commit 0e976e1)
@zpao Note that this requires a Systrace change in RN I haven’t submitted yet. |
Summary: This brings RN up to date with facebook/react#7472 (scheduled for React 15.3.1). If you use React 15.3.1 with RN without this patch, Systrace output will lack the reconciler events. (Since it’s a niche feature it didn’t seem to me that full backward compat is necessary so I just removed old hooks. This won’t cause crashes—it’s just you won’t get events in Systrace if you use new React but old RN.) Closes #9383 Differential Revision: D3738463 Pulled By: spicyj fbshipit-source-id: 791cdbc5558666a101fa403f4e7852f700038fc9
Our DEV performance suffers because we have too many hook events right now.
I want to cut down on their number and be stricter in the future about adding more events.
I removed:
onInstantiateComponent
onSetParent
onComponentHasMounted
onComponentHasUpdated
onBeginReconcilerTimer
onEndReconcilerTimer
Instead, I added
onBeforeUnmountComponent
, and movedparentID
intoonBeforeMountComponent
.As a result we now have a very simple (and small) hook event footprint for reconciliation:
onBeforeMountComponent
andonMountComponent
onBeforeUpdateComponent
andonUpdateComponent
onBeforeUnmountComponent
andonUnmountComponent
Basically a pair of events for every operation we support.
This will reqiure changes to RN and WTF integration.