Skip to content

fix: dispose performance#6894

Merged
BeksOmega merged 12 commits intoRaspberryPiFoundation:developfrom
BeksOmega:fix/dispose-performance
Mar 16, 2023
Merged

fix: dispose performance#6894
BeksOmega merged 12 commits intoRaspberryPiFoundation:developfrom
BeksOmega:fix/dispose-performance

Conversation

@BeksOmega
Copy link
Copy Markdown
Contributor

@BeksOmega BeksOmega commented Mar 14, 2023

The basics

  • I branched from develop
  • My pull request is against develop
  • My code follows the style guide
  • I ran npm run format and npm run lint

The details

Resolves

Fixes #6890

Proposed Changes

Improves performance of deleting blocks.

See #6890 for previous performance. The new performance is ~300ms total, and ~100ms for checkAndDelete.

Reason for Changes

Speeeed

Test Coverage

Manual testing + fixing failing tests.

Added one test to check that blocks do not receive their own delete events.

Documentation

N/A

Additional Information

We save an extra 20ms after #6876 is merged.

Best to review this commit-wise since there is some code reorganization.

@BeksOmega BeksOmega requested a review from a team as a code owner March 14, 2023 20:17
@BeksOmega BeksOmega requested a review from NeilFraser March 14, 2023 20:17
@github-actions github-actions Bot added the PR: fix Fixes a bug label Mar 14, 2023
@github-actions github-actions Bot added PR: fix Fixes a bug and removed PR: fix Fixes a bug labels Mar 14, 2023
Copy link
Copy Markdown
Collaborator

@rachel-fenichel rachel-fenichel left a comment

Choose a reason for hiding this comment

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

Overall looks good. I have some questions about how certain changes preserve old behaviour, but I'll try to find you to discuss in-person.

Comment thread core/block.ts
Comment thread core/block.ts
if (this.isDeadOrDying()) return;

if (this.onchangeWrapper_) {
this.workspace.removeChangeListener(this.onchangeWrapper_);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Will the existing change listener trigger on the call to unplug on line 318?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added the removal to dispose as well, with explanatory comment.

Comment thread core/icon.ts Outdated
Comment thread core/field.ts
Comment thread core/block_animations.ts Outdated
Comment thread core/block.ts Outdated
for (let i = 0, input; input = this.inputList[i]; i++) {
input.dispose();
}
[...this.childBlocks_].forEach((c) => c.disposeInternal());
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This used to use the original array and go backwards. Now it uses a copy and goes forward. Why the change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So we discussed yesterday, and I said the issue was that setParent(null) updates the childBlocks_ of the parent block. So calling dispose on children would mutate the array we were looping over. We could either deal with this by looping backwards (as previous) or by looping over a copy that doesn't get mutated.

However! I checked it again after we chatted and since we're no longer calling unplug on every block, we're also not calling setParent(null) on every block. So the array isn't being mutated at all, and we can just loop over it directly =)

@BeksOmega BeksOmega requested review from rachel-fenichel and removed request for NeilFraser March 15, 2023 22:23
@BeksOmega BeksOmega merged commit 670f7da into RaspberryPiFoundation:develop Mar 16, 2023
@BeksOmega BeksOmega mentioned this pull request Apr 5, 2023
4 tasks
@BeksOmega BeksOmega deleted the fix/dispose-performance branch May 3, 2023 20:40
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.

Improve performance of deleting blocks

3 participants