-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
fix: bump neighbours performance regression #7748
Conversation
6582105
to
7139b6b
Compare
7139b6b
to
323fb7a
Compare
323fb7a
to
13ae6ca
Compare
@@ -963,7 +963,8 @@ export class Gesture { | |||
eventUtils.setGroup(true); | |||
} | |||
const newBlock = this.flyout.createBlock(this.targetBlock); | |||
newBlock.scheduleSnapAndBump(); | |||
newBlock.snapToGrid(); |
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.
this feels suspicious to me... if we're telling external users they don't need to call bumpNeighbors
directly, we shouldn't either when we're creating a new block in this manner.
I don't think we need it anyway. createBlock
uses json serialization to append
new block to the workspace. append
will eventually queue a render on the block, which will now call these two things. so calling them here should be redundant, I think.
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.
Ah you're right, this is actually a good case for someone calling this externally, so I've undeprecated it.
The problem here is that createBlock
forces an immediate render (because we always force an immediate render when deserializing). But at the time the render is triggered, the blockj isn't guaranteed to be in the correct place, so the bump isn't guaranteed to be correct.
This would be fixed if createBlock
just deserialized at the correct spot, but since it's overridable, that's not possible to guarantee.
It would also be possible to trigger a bumping after every block move, but this could easily break external developers' functions for "cleaning up" the workspace. I believe it would even break our built-in context menu option for cleanup, because we space blocks based on the minimum block height, not the bump distance.
So our only option is to snap to the grid after deserializing, and then trigger the bump manually.
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.
createBlock
is currently internal, which... is one of the ones that is incorrect because it's also part of the IFlyout
interface. But I think it might be fair to fix this in our implementation of createBlock
and then add it as a requirement that anyone overriding createBlock
needs to take into account? Because this is going into a major I feel comfortable adding that new constraint. We could even fix it in placeNewBlock
and/or positionNewBlock
and then make those methods protected instead of private, so that subclasses of Flyout
could use them and use our fixed logic, making it pretty easy on the developer to get this right.
By "just deserialized at the correct spot" do you mean we'd calculate the position of where the block should go before deserializing (so add the correct coordinates to the json instead of calling moveTo
afterwards)? If so I think the approach above could make sense.
Otherwise or if that actually doesn't make sense, then leaving it undeprecated makes sense as well.
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.
So the specific case for createBlock
could be worked around by making a breaking change, but I still don't think it's fixable in general.
Folks could still want to move blocks programmatically, and then trigger bumpin neighbours on them, and that requires the bumpNeighbours
method to be public.
I don't think making the break in createBlock
makes sense given that, but will await your opinions.
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.
Okay, that makes sense too. If we can't trigger it on every block move then it would need to be public regardless. I'm fine with leaving createBlock
alone then.
Found an issue with insertion markers causing bumping that I have a few solutions for, but no clear winner. I'm going to let it sit in my brain over the long weekend and then come back to this tuesday. |
559ca7c
to
336faa3
Compare
* Schedule snapping to grid and bumping neighbours to occur after a brief | ||
* delay. | ||
* | ||
* @internal |
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.
Unfortunately we use this in a plugin :/ This also seems like a likely function that people would be using even though it's marked internal. How would you feel about deprecating it instead and removing it at a future date?
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.
How do you feel about making scheduleSnapAndBump
public instead? Since we already established people may want to bump neighbours after programatically moving their blocks (makes sense they'd want to snap too).
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.
That sounds great!
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.
But I think the comment may be inaccurate now, there's not a delay inherent to this other than just the rendering queue. right?
* fix: move bumping neighbours to the end of rendering * chore: remove scheduleSnapAndBump * chore: remove references to bumpNeighbours * chore: work on fixing tests * fix: bump neighbours event grouping * chore: format * chore: readd deprecation import * fix: move event ordering * chore: undeprecate bumpNeighbours * fix: bumping during drag due to insertion markers * chore: tests * chore: PR feedback * chore: docs * chore: typo
The basics
The details
Resolves
N/A
Proposed Changes
Makes it so that
bumpNeighbours
is called as part of the rendering cycle.Reason for Changes
bumpNeighbours
because it just happens whenever the block changes shape.rendered
meaning #7747 . The regression was thatbumpNeighbours
was being called on every single block initialization action during deserialization, which meant a ton ofsetTimeout
calls, which were slowing everything down. MakingbumpNeighbours
part of serialization gets rid of thesesetTimeout
calls.Test Coverage
Manually tested.
Manually profiled performance.
Also covered by some existing unit tests (caught the issue with event grouping!)
Documentation
N/A
Additional Information
Dependent on #7747