stacks: refactor plan, state, and removed tracking for efficient lookups #36850
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR updates the stack plan, stack state, and removed tracking structures to store components within a nested tree structure instead of a single flat map entry.
This means we can now retrieve components by embedded stack address efficiently instead of having to iterate over the entire collection of components every time. Lookups to individual components now have to traverse the tree, but the address is still precise giving a direct map look up at every stage of the address which is still acceptable.
The removed tracking changes are similar, where instead of four flat maps of various removed blocks, the embedded blocks are now stored in a nested removed structure. This means we write the removed structure once when everything is discovered the first time, and then it can be reused in later iterations. This also tidies up the next piece of work (orphaned removed blocks) by making it easier to retrieve removed blocks by direct addresses.