Skip to content
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

Merged
merged 14 commits into from
Jan 17, 2024

Conversation

BeksOmega
Copy link
Collaborator

@BeksOmega BeksOmega commented Jan 5, 2024

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

  1. You no longer have to remember to call bumpNeighbours because it just happens whenever the block changes shape.
  2. Alleviates a performance regression caused by fix!: rendered meaning #7747 . The regression was that bumpNeighbours was being called on every single block initialization action during deserialization, which meant a ton of setTimeout calls, which were slowing everything down. Making bumpNeighbours part of serialization gets rid of these setTimeout 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

@BeksOmega BeksOmega added the deprecation This PR deprecates an API. label Jan 5, 2024
@BeksOmega BeksOmega requested a review from a team as a code owner January 5, 2024 18:18
@BeksOmega BeksOmega requested a review from NeilFraser January 5, 2024 18:18
@github-actions github-actions bot added PR: fix Fixes a bug and removed deprecation This PR deprecates an API. labels Jan 5, 2024
@BeksOmega BeksOmega marked this pull request as draft January 5, 2024 18:19
@BeksOmega BeksOmega changed the base branch from rc/v11.0.0 to v11-breaks January 8, 2024 22:24
@github-actions github-actions bot added PR: fix Fixes a bug and removed PR: fix Fixes a bug labels Jan 8, 2024
@BeksOmega BeksOmega force-pushed the fix/bump-neighbours branch from 6582105 to 7139b6b Compare January 8, 2024 22:27
@BeksOmega BeksOmega mentioned this pull request Jan 9, 2024
1 task
@github-actions github-actions bot added PR: fix Fixes a bug and removed PR: fix Fixes a bug labels Jan 9, 2024
@BeksOmega BeksOmega force-pushed the fix/bump-neighbours branch from 7139b6b to 323fb7a Compare January 9, 2024 22:06
@github-actions github-actions bot added PR: fix Fixes a bug and removed PR: fix Fixes a bug labels Jan 9, 2024
@BeksOmega BeksOmega force-pushed the fix/bump-neighbours branch from 323fb7a to 13ae6ca Compare January 10, 2024 19:15
@BeksOmega BeksOmega marked this pull request as ready for review January 10, 2024 19:19
@@ -963,7 +963,8 @@ export class Gesture {
eventUtils.setGroup(true);
}
const newBlock = this.flyout.createBlock(this.targetBlock);
newBlock.scheduleSnapAndBump();
newBlock.snapToGrid();
Copy link
Contributor

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.

Copy link
Collaborator Author

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.

Copy link
Contributor

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.

Copy link
Collaborator Author

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.

Copy link
Contributor

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.

@BeksOmega
Copy link
Collaborator Author

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.

@BeksOmega BeksOmega assigned maribethb and unassigned NeilFraser Jan 12, 2024
@BeksOmega BeksOmega requested review from maribethb and removed request for NeilFraser January 12, 2024 22:08
@BeksOmega BeksOmega force-pushed the fix/bump-neighbours branch from 559ca7c to 336faa3 Compare January 16, 2024 19:34
* Schedule snapping to grid and bumping neighbours to occur after a brief
* delay.
*
* @internal
Copy link
Contributor

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?

Copy link
Collaborator Author

@BeksOmega BeksOmega Jan 16, 2024

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).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds great!

Copy link
Contributor

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?

@BeksOmega BeksOmega merged commit 00faba2 into google:v11-breaks Jan 17, 2024
6 checks passed
BeksOmega added a commit that referenced this pull request Jan 23, 2024
* 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
@maribethb maribethb mentioned this pull request May 15, 2024
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: fix Fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants