-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Thread always done #2148
base: develop
Are you sure you want to change the base?
Thread always done #2148
Conversation
7fe1bba
to
620e31e
Compare
a81f1bf
to
8768fa3
Compare
@kchadha I refactored this PR so its now standalone. This still achieves the goal that a thread with an empty stack array or stackFrame array has a status of DONE. This may leave the thread's peekStack at null and a status that is not DONE as long as the stack/stackFrames arrays are not length 0. To achieve that it does a few added things that the prior dependee branches did.
Some logic in runtime.js and execute.js perform sequencer logic for hat and promise support. That logic is now either an existing thread method, a new sequencer method, or handled by Sequencer.stepThread.
Add a method to pop a thread's stack until it is exhausted, hits a loop or non-null block. The method's logic is reduced from its prior form to loop until the thread's status changes or peekStack is not null.
Part of unwrapStack replaces some warpMode consideration logic with setting the thread status to yield. Other code in stepThread can then consider if the yielded loop block should execute anyways due to warpMode or other cases.
Reorder the logic so cases using continue and return and be removed and allow the loop to execute normally and not exit prematurely. |
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.
Some minor comments/changes requested, and it seems this branch needs to be updated against current develop to pull in changes from #2126
src/engine/sequencer.js
Outdated
} | ||
} | ||
// Indicate the block that just executed. | ||
thread.blockGlowInFrame = currentBlockId; |
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.
Shouldn't this happen inside the while loop?
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.
Hmm. blockGlowInFrame
is one of those thread parts that I thought was odd to be in sequencer. I think it'd make the most sense being next to wherever requestScriptGlowInFrame is set.
Looking back at this, I've done just that. I moved blockGlowInFrame into execute alongside requestScript before the loops in execute(). That'll update the blockGlowInFrame every time we run a block.
Virtual machine only blocks allow us to ensure status === DONE when a thread is DONE. So We do not need to test if the stack is length 0 or if isKilled is set. Just make sure status === DONE.
8768fa3
to
922bceb
Compare
922bceb
to
bb25a58
Compare
@mzgoddard, these changes are almost good to go, but I did notice that some stacks aren't glowing (they are in production). E.g. in this project 288115558, Sprite1 has a |
Resolves
General performance around iterating threads during a step.
Proposed Changes
Depends on #2145 and #2147.This PR is now standalone and does not depend on other PRs.
Reason for Changes
The current code base doesn't actually remove the thread so I'm not sure we need this additional data point.
Removing isKilled lets us remove the isKilled loop at the beginning of _step. Which currently, must loop over all threads.
The one way isKilled threads are configured that way is through stop thread, which also sets their status to DONE.
Generally most threads will be RUNNING and not YIELD_TICK. We can have the special case after the primary case in the same if/else branch chain and if it is YIELD_TICK, i-- to run it again and have the RUNNING branch activate. This removes a branch test from most thread execution.
The work in the depending PRs get us to a point where status === DONE when stack is length 0. So they should be synamous and we can use the one test.