-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
Conversation
fbec958
to
9dbb39e
Compare
@@ -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; |
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 Update
s, whose callback
type is Function | null
, but now we're iterating through a list of functions.
} | ||
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.
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
@@ -59,6 +59,7 @@ export type UpdateQueue = { | |||
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.