Skip to content

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

Open

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.

Activity

  1. tracygardner commented on Apr 20, 2026

    @tracygardner
    Contributor

    There's a global blockly event handler in https://github.com/flipcomputing/flock/blob/main/main/blockhandling.js. This can be moved there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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