defer checkBounds during batch block operations to fix#5797
Open
Ashutoshx7 wants to merge 1 commit intosugarlabs:masterfrom
Open
defer checkBounds during batch block operations to fix#5797Ashutoshx7 wants to merge 1 commit intosugarlabs:masterfrom
Ashutoshx7 wants to merge 1 commit intosugarlabs:masterfrom
Conversation
…yout recalculation Previously, _moveBlock() called checkBounds() on every invocation, and �djustDocks() recursively called _moveBlock() for every connected block. Since checkBounds() iterates the entire blockList, this created O(N×M) complexity (N = blocks in stack, M = total blocks) for every dock adjustment, stack move, or block reconnection. This commit introduces a deferred batching mechanism: - _beginDeferCheckBounds() / _endDeferCheckBounds() suppress intermediate checkBounds() calls and run a single check when the batch completes. Supports nesting for safety. - �djustDocks() automatically defers on the outermost call, so all recursive _moveBlock() invocations skip redundant checkBounds iterations. - moveStackRelative(), moveAllBlocksExcept(), and updateBlockPositions() also wrap their loops with the deferred mechanism. - Standalone _moveBlock() / moveBlockRelative() calls (outside a deferred window) continue to call checkBounds() immediately, preserving existing behavior for single-block moves. For a project with 200 blocks where adjustDocks touches a 20-block stack, this reduces checkBounds iterations from ~4,000 (20 × 200) to just 200 (a single scan), a 20x improvement in layout recalculation overhead. Fixes sugarlabs#5650
Contributor
|
✅ All Jest tests passed! This PR is ready to merge. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #5650
Problem
_moveBlock() calls checkBounds() on every invocation, and adjustDocks() recursively calls _moveBlock() for every connected block. Since checkBounds() iterates the entire blockList each time, this creates O(N x M) complexity per dock adjustment — where N is the number of blocks in the stack and M is total blocks in the project. The same pattern exists in moveStackRelative(), moveAllBlocksExcept(), and updateBlockPositions().
For a 200-block project with a 20-block stack, that's 4,000 iterations per adjustment instead of 200.
Solution
Introduced a deferred batching mechanism: _beginDeferCheckBounds() and _endDeferCheckBounds() suppress intermediate checkBounds() calls and run a single check when the batch completes. The mechanism supports nesting.
One file changed, 70 insertions, 3 deletions. No public API changes.
Testing