Skip to content

addUndoHandler change listener is O(n²) on block deletion #560

@lawsie

Description

@lawsie

Is your feature request related to a problem? Please describe.
Issue raised by Claude Sonnet 4.6:

In gizmos.js, addUndoHandler registers a BLOCK_DELETE change listener. When a gizmo-created block is deleted, the listener iterates through all blocks in the DO section to check if the section is now empty. This scan runs once per deleted block — but Blockly fires a BLOCK_DELETE event for every block in a cascade delete, so deleting a parent with many children triggers a full rescan for each one.

For scenes with many blocks this could cause noticeable lag on delete. The fix would be to batch the cleanup using Blockly.Events.setGroup or by deferring the scan with a setTimeout so all deletions in the same event group are processed in one pass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions