Skip to content

Child nodes are cleared using an O(n^2) loop #1888

@TrevorBurnham

Description

@TrevorBurnham

In several different parts of the codebase, all children are removed from a parent using a loop like this:

while (childNodes.length) removeChild(childNodes[0])

Since each removal invokes splice(0, 1) on the child array, you pay the price of shifting every remaining child on each loop iteration. Hence, the number of array-shifting operations is O(n^2) with respect to the number of children.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions