-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix: dispose performance #6894
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
Merged
BeksOmega
merged 12 commits into
RaspberryPiFoundation:develop
from
BeksOmega:fix/dispose-performance
Mar 16, 2023
Merged
fix: dispose performance #6894
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4802f96
fix: improve dispose performance
BeksOmega 571d47f
chore: cleanup dispose functions
BeksOmega 477ee3c
chore: split dispose into dispose and disposeInternal
BeksOmega fa1db23
chore: remove unnecessary node removal
BeksOmega 7949c74
fix: remove unnecessary unbinding of event listeners
BeksOmega 1888a4c
fix: readd skipping event construction
BeksOmega dd225f0
chore: work on fixing tests
BeksOmega 9fd7f63
chore: fix remaining test failures
BeksOmega 138d3a0
chore: format
BeksOmega a2ba015
chore: typo
BeksOmega 89cb43f
fix: first pass of PR comments
BeksOmega c9828e4
chore: remove TODO
BeksOmega File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -313,44 +313,45 @@ export class Block implements IASTNodeLocation, IDeletable { | |
| * @suppress {checkTypes} | ||
| */ | ||
| dispose(healStack: boolean) { | ||
| if (this.isDeadOrDying()) { | ||
| return; | ||
| } | ||
| // Terminate onchange event calls. | ||
| if (this.isDeadOrDying()) return; | ||
|
|
||
| // Dispose of this change listener before unplugging. | ||
| // Technically not necessary due to the event firing delay. | ||
| // But future-proofing. | ||
| if (this.onchangeWrapper_) { | ||
| this.workspace.removeChangeListener(this.onchangeWrapper_); | ||
| } | ||
|
|
||
| this.unplug(healStack); | ||
| if (eventUtils.isEnabled()) { | ||
| // Constructing the delete event is costly. Only perform if necessary. | ||
| eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_DELETE))(this)); | ||
| } | ||
| eventUtils.disable(); | ||
| this.workspace.removeTopBlock(this); | ||
| this.disposeInternal(); | ||
| } | ||
|
|
||
| /** | ||
| * Disposes of this block without doing things required by the top block. | ||
| * E.g. does not fire events, unplug the block, etc. | ||
| */ | ||
| protected disposeInternal() { | ||
| if (this.isDeadOrDying()) return; | ||
|
|
||
| if (this.onchangeWrapper_) { | ||
| this.workspace.removeChangeListener(this.onchangeWrapper_); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will the existing change listener trigger on the call to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added the removal to |
||
| } | ||
|
|
||
| eventUtils.disable(); | ||
| try { | ||
| // This block is now at the top of the workspace. | ||
| // Remove this block from the workspace's list of top-most blocks. | ||
| this.workspace.removeTopBlock(this); | ||
| this.workspace.removeTypedBlock(this); | ||
| // Remove from block database. | ||
| this.workspace.removeBlockById(this.id); | ||
| this.disposing = true; | ||
|
|
||
| // First, dispose of all my children. | ||
| for (let i = this.childBlocks_.length - 1; i >= 0; i--) { | ||
| this.childBlocks_[i].dispose(false); | ||
| } | ||
| // Then dispose of myself. | ||
| // Dispose of all inputs and their fields. | ||
| for (let i = 0, input; input = this.inputList[i]; i++) { | ||
| input.dispose(); | ||
| } | ||
| this.childBlocks_.forEach((c) => c.disposeInternal()); | ||
| this.inputList.forEach((i) => i.dispose()); | ||
| this.inputList.length = 0; | ||
| // Dispose of any remaining connections (next/previous/output). | ||
| const connections = this.getConnections_(true); | ||
| for (let i = 0, connection; connection = connections[i]; i++) { | ||
| connection.dispose(); | ||
| } | ||
| this.getConnections_(true).forEach((c) => c.dispose()); | ||
| } finally { | ||
| eventUtils.enable(); | ||
| if (typeof this.destroy === 'function') { | ||
|
|
||
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
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
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
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
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
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
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.