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

Don't count the time inside flushes towards lifecycle hooks #6860

Merged
merged 2 commits into from
May 25, 2016
Merged

Don't count the time inside flushes towards lifecycle hooks #6860

merged 2 commits into from
May 25, 2016

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented May 24, 2016

Fixes #6842.

We keep the existing behavior of testing for matching onBeginLifeCycleTimer/onEndLifeCycleTimer calls, but we push the current timer onto the stack if we enter a flush. This solves an issue with portals which cause updates while a lifecycle timer is already running.

I chose to subtract the time spent in the flush from the time counted towards the lifecycle method because it would artificially inflate the “total” time of the component due to all the components inside the portal, so it would skew the exclusive table.

Fixes #6842.

We keep the existing behavior of testing for matching `onBeginLifeCycleTimer`/`onEndLifeCycleTimer` calls, but we push the current timer onto the stack if we enter a flush.
This solves an issue with portals which cause updates while a lifecycle timer is already running.

I chose to subtract the time spent in the flush from the time counted towards the lifecycle method because it would artificially inflate the “total” time of the component due to all the components inside the portal, so it would skew the exclusive table.
// - in the nested flush, we call it twice before and after <Foo /> rendering. (n = 3)
// - we capture the time when we exit a nested flush (n = 4)
// - we capture the time we exit componentDidMount (n = 5)
// Time spent in componentDidMount = (5 - 0 - (4 - 3)) = 4.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not super happy about this. If it’s too brittle, I can probably do something nasty like call ReactDOM.render() 100 times and assert that the lifecycle own time is smaller than the inner element’s render time.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for me.

@gaearon
Copy link
Collaborator Author

gaearon commented May 24, 2016

Sending this one your way too @spicyj 😄

// This is how we get 4 as a number with the performanceNow() mock:
// - we capture the time we enter componentDidMount (n = 0)
// - we capture the time when we enter a nested flush (n = 1)
// - in the nested flush, we call it twice before and after <Foo /> rendering. (n = 3)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add a comma after "twice" or else it sounds like it's called twice before and twice after

@gaearon gaearon merged commit 8d7161e into facebook:master May 25, 2016
@ghost
Copy link

ghost commented May 25, 2016

@gaearon updated the pull request.

@zpao zpao added this to the 15-next milestone Jun 1, 2016
@gaearon gaearon deleted the perf-nested-fix-2 branch June 6, 2016 20:04
zpao pushed a commit to zpao/react that referenced this pull request Jun 8, 2016
…#6860)

* Don't count the time inside flushes towards lifecycle hooks

Fixes facebook#6842.

We keep the existing behavior of testing for matching `onBeginLifeCycleTimer`/`onEndLifeCycleTimer` calls, but we push the current timer onto the stack if we enter a flush.
This solves an issue with portals which cause updates while a lifecycle timer is already running.

I chose to subtract the time spent in the flush from the time counted towards the lifecycle method because it would artificially inflate the “total” time of the component due to all the components inside the portal, so it would skew the exclusive table.

* Fix up the comment

(cherry picked from commit 8d7161e)
zpao pushed a commit that referenced this pull request Jun 14, 2016
* Don't count the time inside flushes towards lifecycle hooks

Fixes #6842.

We keep the existing behavior of testing for matching `onBeginLifeCycleTimer`/`onEndLifeCycleTimer` calls, but we push the current timer onto the stack if we enter a flush.
This solves an issue with portals which cause updates while a lifecycle timer is already running.

I chose to subtract the time spent in the flush from the time counted towards the lifecycle method because it would artificially inflate the “total” time of the component due to all the components inside the portal, so it would skew the exclusive table.

* Fix up the comment

(cherry picked from commit 8d7161e)
@zpao zpao modified the milestones: 15-next, 15.2.0 Jun 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants