fix: add timeouts to delay expensive mutation operations #6149
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.
The basics
npm run format
andnpm run lint
The details
Resolves
Work on #6131
Proposed Changes
Delays expensive operations using setTimeout so that:
compose()
multiple times for things that won't be rendered.Behavior Before Change
~188ms for
updateWorkspace
to run, which was required to complete before the first frame could be drawn.Behavior After Change
~35ms for
updateWorkspace
to run, after which the mutated block is drawnThen ~20ms for
resizeBubble_
to run, after which the newly positioned/sized bubble is drawnmutating-2.txt
Reason for Changes
Make the UI feel more responsive.
Test Coverage
My main concern with this was that adding the delays would cause a race condition (or similar problem) related to undo and redo. Tested using the following steps:
Tested on:
Documentation
N/A
Additional Information
I tried to speed up
resizeBubble_
but I couldn't figure out a way to remove the layout thrashing. The issue is our operations look like:Afaict 1 and 4 are unavoidable, unless we really want to refactor how the metrics manager works (eg having it calculate based on the
width
andheight
properties of blockSvgs, rather than using the browser's measurement).We could get rid of 2 (which is triggered by this call) by changing
this.shape_
to be aBlockly.Rect
instead of anSVGElement
. But this would be a breaking change.We could also probably speed up
compose
and thereforeupdateWorkspace_
by not completely tearing down the block, which requires disposing and then re-creating all of the DOM elements associated with a block. But that's a much bigger refactor than I was looking to do.