WIP: Add compiler deoptimization infrastructure for live editing - #353
WIP: Add compiler deoptimization infrastructure for live editing#353LuYifei2011 wants to merge 5 commits into
Conversation
|
This might affect performance for people who don't want this. Maybe this should be a runtime option? |
|
Write a design document (with a lot of human words, not ai slop) before you waste a billion tokens on something that may not be interesting to merge |
It might be poorly written. 🙏
|
Design DocumentBackground / Problem StatementCurrently, TurboWarp clears its cache after a block is modified, ensuring newly started threads use the latest blocks, while already running threads continue to use the old blocks. This solution aims to make already running compiled threads fall back to interpreted execution so they can pick up live edits. Target DesignWhen is Fallback Triggered?When a target's Block Container is modified, consistent with the existing cache invalidation behavior. Will Newly Started Threads Use Compiled or Interpreted Execution After Block Modification?Compiled. Consistent with the previous implementation. When Will Running Threads Switch to Interpreted Execution?When the thread reaches a
If these conditions are not all met, the old compiled code will continue to run. Design BoundariesThis solution is only responsible for the switch from compiler execution to interpreter execution, including deciding when to switch and performing state handover. After the switch, modifications and deletions of blocks are handled by the interpreter and are not within the scope of this solution. This solution does not guarantee that modifications will take effect immediately; when they take effect depends on when the thread reaches the safe switching point. I used Google Translate to translate most of this design document into English, so there may be some translation errors. By the way, I understand your concerns about AI-generated content, and I apologize for the overly long AI-generated content I posted previously. I did used AI to help me understand parts of scratch-vm more quickly and to discuss some technical questions related to this PR. However, I wrote most of the code, and I have reviewed and understand the proposed design and the code in this PR. |
|
ok. how do you plan to handle cases like:
these are the actually interesting cases, you need to have a plan from the start do you have a sense what the expected performance hit would be from the bookkeeping and code? why is falling back to the interpreter preferred over a way to make the compiler handle it appropriately? forkphorus-style continuation-passing in principle can support live script reloading while still being order-of-magnitude speed improvement over the interpreter. there are other ways you can imagine that this is possible too. why not do those? |
|
will you plan to implement some UI explaining why someone's script becomes 100x slower after making any change in an unrelated part of the sprite that may not even be used by the affected thread? edge-activated hats are compiled for a while now: where does the evaluation phase part of that fit into this? |
|
Additional notes:
I think we could maintain a runtime-side procedure call stack to record the information needed to reconstruct interpreter frames (such as parameters) and update this stack when entering or exiting custom blocks.
I would not allow de-optimization when executing custom extension blocks. Most extensions don't have
I don't think those things should be re-evaluated. My original plan was to avoid de-optimization within reporter blocks and only allow switching back to interpreted execution within supported stack blocks or C-blocks, as this simplifies the implementation.
I don't have benchmark numbers yet, but I anticipate the main performance impacts will stem from:
We could provide a toggle for de-optimization and include some explanatory notes.
Perhaps we could switch to finer-grained detection to allow for more precise de-optimization.
translated by Google Translate |
Related Discussion
#16 (comment)
Proposed Changes
This PR explores allowing compiled scripts to deopt back to the interpreter without restarting them.
Implemented:
repeatandwhileloopsNot implemented:
Reason for Changes
Currently, compiled scripts continue executing old generated code after the project is edited. This is a prototype for switching compiled scripts back to the interpreter at safe points instead of restarting them.
Test Coverage
repeatloopswhileloops