With 10,000 objects selected, object.move walked the document's tree five
times and looked each object up by id three times. It now walks the tree
three times and looks each object up once.
- The selected roots (for the menus, for Move, Rotate, Scale and the
other transforms, for Copy and Cut, and inside an isolated group) are
put in paint order and reduced to their top-level objects from one walk
instead of two.
- A transform finds the objects' places once for Transform Patterns and
for the edit, instead of once for each.
- After a transform, the check for a pixel-aligned compound path reads
the parent at the object's place instead of looking the object and its
parent up by id.
selected_roots put the selected objects in paint order and dropped the
inner ones, two walks of the document, every time a command or an
enabled check asked. A rebuild of the menus asks many times for one
selection. The roots are now kept on the thread with the document
version (held weakly, so its address is not reused) and the selected
objects, and found again only when either changes.
With 10,000 rectangles selected, a menu rebuild after Select All went
from about 500 ms to about 340 ms on the build host.
Cut with direct-selected anchors or segments removed each object selected
whole, and each path it left with no segment, with its own remove. Every
removal shifted the siblings after it, so later lookups walked the
document's tree again. With 2,000 roots removed whole, the old loop
walked the tree 10,005 times.
These removals now go through the same batch that already places the
surviving pieces, which rebuilds the children of each layer or group
once, and compound paths left with no members are removed after it. A
compound path left with one member stays a compound path. The document,
the selection, the clipboard and the undo step are the same as before.
With 2,000 of 10,000 squares on one layer selected whole and two anchors
of another picked, Cut walks the tree 8 times instead of 10,005 and
takes a median of 11 ms of CPU time instead of 573 ms (release build on
Linux, seven alternating runs in one process).