-
Notifications
You must be signed in to change notification settings - Fork 50k
[Fiber] Remove callbackList field from Fiber #8728
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
Conversation
fbec958 to
9dbb39e
Compare
| altQueue.last = sourceQueue.last; | ||
| altQueue.hasForceUpdate = sourceQueue.hasForceUpdate; | ||
| altQueue.callbackList = sourceQueue.callbackList; | ||
| altQueue.isProcessing = sourceQueue.isProcessing; |
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.
Why are we setting isProcessing here, but didn’t set before? Is this fixing a bug?
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.
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)
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.
Got it
| // Queue is now empty | ||
| queue.callbackList = callbackList; | ||
|
|
||
| if (!queue.first && !queue.callbackList && !queue.hasForceUpdate) { |
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.
Minor nit: do you need to dereference queue.callbackList here? Can you use callbackList directly?
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.
Yeah that works
| let update = callbackList.first; | ||
| while (update) { | ||
| const callback = update.callback; | ||
| if (typeof callback === 'function') { |
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.
Was this check unnecessary? Are we validating early now?
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.
Brian added validateCallback checks whenever a callback is enqueued
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.
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.
| const callback = callbackList[i]; | ||
| callback.call(context); | ||
| } | ||
| finishedWork.callbackList = null; |
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.
Why do we not need to reset it now?
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.
Didn't need it before either, really. The field gets reset whenever we beginWork.
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.
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.
gaearon
left a comment
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.
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.
9dbb39e to
288a4c4
Compare
| first: Update | null, | ||
| last: Update | null, | ||
| hasForceUpdate: boolean, | ||
| callbackList: null | Array<Callback>, |
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.
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?
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.
Sure, though may I ask why it's ok to use arrays for context but not here?
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.
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.
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.
Moves it to UpdateQueue instead so that we don't waste memory for components that don't have update queues.
Unobservable, so no tests.