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

[Fiber] Remove callbackList field from Fiber #8728

Merged
merged 2 commits into from
Jan 10, 2017

Conversation

acdlite
Copy link
Collaborator

@acdlite acdlite commented Jan 9, 2017

Moves it to UpdateQueue instead so that we don't waste memory for components that don't have update queues.

Unobservable, so no tests.

@@ -122,6 +125,8 @@ function cloneUpdateQueue(alt : Fiber, fiber : Fiber) : UpdateQueue | null {
altQueue.first = sourceQueue.first;
altQueue.last = sourceQueue.last;
altQueue.hasForceUpdate = sourceQueue.hasForceUpdate;
altQueue.callbackList = sourceQueue.callbackList;
altQueue.isProcessing = sourceQueue.isProcessing;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are we setting isProcessing here, but didn’t set before? Is this fixing a bug?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No bug, just noticed it wasn't being copied and I added it for consistency's sake. Although actually, callbackList, isProcessing, and hasForceUpdate can be reset when cloning. I'll do that instead. #8728 (comment)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Got it

// Queue is now empty
queue.callbackList = callbackList;

if (!queue.first && !queue.callbackList && !queue.hasForceUpdate) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor nit: do you need to dereference queue.callbackList here? Can you use callbackList directly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah that works

let update = callbackList.first;
while (update) {
const callback = update.callback;
if (typeof callback === 'function') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Was this check unnecessary? Are we validating early now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Brian added validateCallback checks whenever a callback is enqueued

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also the type is stricter now. Previously we iterated through a list of Updates, whose callback type is Function | null, but now we're iterating through a list of functions.

}
finishedWork.callbackList = null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we not need to reset it now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Didn't need it before either, really. The field gets reset whenever we beginWork.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This reminds me though that in cloneUpdateQueue, some of those fields should just be reset since by the time we clone from current, they're no longer valid. Not an observable change but it's what cloneFiber does so better to be consistent.

Copy link
Collaborator

@gaearon gaearon left a comment

Choose a reason for hiding this comment

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

Looks good, left a few comments for parts I don't understand. Feel free to merge if there are good answers. :-)

Moves it to UpdateQueue instead so that we don't waste memory for
components that don't have update queues.
Similar to what cloneFiber does. No change in behavior, but it's more
consistent this way.
@acdlite acdlite merged commit 00be2e4 into facebook:master Jan 10, 2017
@@ -59,6 +59,7 @@ export type UpdateQueue = {
first: Update | null,
last: Update | null,
hasForceUpdate: boolean,
callbackList: null | Array<Callback>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This used to use a linked list like all the other structures. That requires dynamic reallocation as it grows. It also requires us to take on a dependency on such an implementation. This might matter if we make a WASM port.

Would it make sense to just use a simple linked list here too, just for consistency?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, though may I ask why it's ok to use arrays for context but not here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

In context it is a fixed general stack. In normal use it never gets reallocated or expanded. The wasm implementation can be as easy as a fixed one time linear allocation. Where as this is dynamically allocated and growing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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