Skip to content

[Fiber] PureComponent #8118

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

Merged
merged 1 commit into from
Oct 27, 2016
Merged

[Fiber] PureComponent #8118

merged 1 commit into from
Oct 27, 2016

Conversation

acdlite
Copy link
Collaborator

@acdlite acdlite commented Oct 26, 2016

Pretty straightforward. Passes existing tests.

}

const type = workInProgress.type;
if (type.prototype && type.prototype.isPureReactComponent) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorta unfortunate if we need to check this every time. @sebmarkbage is there a place we could store this flag on the fiber?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

I figured we start off with all of these being detected on demand and then we can create optimized paths for common patterns. E.g. for things that have shouldComponentUpdate, and things that are pure components and things that have no update life-cycles etc. by storing that in the tag like @acdlite said.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ideally the element itself could already have this information in its tag so that we don't even have to detect this during mount.

Copy link
Collaborator

@sebmarkbage sebmarkbage Oct 27, 2016

Choose a reason for hiding this comment

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

However, this can explode number of code paths so I figured we might want to optimize for collections of common patterns. For example: isPureComponent + no life-cycles. isPureComponent + only componentDidUpdate/componentWillUnmount but no other life-cycles. That way we can branch early and not do any of the checks. Never schedule update effects etc. EDIT: Although I guess it could also be a bitmask that allows this check to be optimized regardless of other early branches.

Copy link
Collaborator Author

@acdlite acdlite Oct 27, 2016

Choose a reason for hiding this comment

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

I like the bitmask idea

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe let's wait on the bitmap thing for now until we know the layout we want for it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh yeah I didn't mean I would add it now :D

!(updateQueue && updateQueue.isForced) &&
workInProgress.memoizedProps !== null &&
!instance.shouldComponentUpdate(newProps, newState)) {
if (!checkShouldComponentUpdate(workInProgress, workInProgress.memoizedProps, newProps, newState)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

line length

@@ -73,6 +74,28 @@ module.exports = function(scheduleUpdate : (fiber: Fiber, priorityLevel : Priori
},
};

function checkShouldComponentUpdate(workInProgress, oldProps, newProps, newState) {
if (oldProps === null ||
Copy link
Collaborator

Choose a reason for hiding this comment

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

formatting please:

if (
  oldProps === null ||
  (workInProgress.updateQueue && workInProgress.updateQueue.isForced)
) {

(Also, may as well pull updateQueue out to a var like before?)

Copy link
Collaborator

Choose a reason for hiding this comment

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

or meh, you can leave it if you like the other way. we're inconsistent.

Copy link
Collaborator

@sophiebits sophiebits left a comment

Choose a reason for hiding this comment

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

lgtm

@acdlite acdlite force-pushed the fiberpurecomponent branch 2 times, most recently from 0ea690a to ecbe4fa Compare October 27, 2016 01:08
@sebmarkbage
Copy link
Collaborator

One more lint.

Passes existing PureComponent tests
@acdlite acdlite force-pushed the fiberpurecomponent branch from ecbe4fa to 59c9464 Compare October 27, 2016 04:03
@acdlite
Copy link
Collaborator Author

acdlite commented Oct 27, 2016

My bad, I had my ESLint plugin disabled.

@acdlite acdlite merged commit e031e0b into master Oct 27, 2016
@acdlite acdlite deleted the fiberpurecomponent branch March 1, 2017 22:05
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.

4 participants