Cut Path: the cut ends are selected with one set call

Cut Path at Selected Anchor Points cleared the selection and then added
each cut path in turn, and each add searched the paths already added, so
selecting the cut ends took time that grows with the square of the number
of cut paths. The command now selects them with one Selection::set call,
which skips repeats through a hash set and keeps the order in which each
path first appears, and then adds each cut end's anchor. The selection is
the same in every field; a new test compares it with the one-by-one build
on open, closed and multi-subpath cuts, long lists and an empty list.

The gain shows on large documents. With the 8 middle anchors of each of
5,000 open paths of 10 anchors selected, building the selection of 40,000
cut ends takes 9.7 ms instead of 232 ms of CPU time, and with 2,000 paths
3.2 ms instead of 39 ms (medians of 7 runs of the new
cut_path_select_bench example, both ways in one process).
This commit is contained in:
dotCooCoo
2026-11-16 10:02:01 -08:00
parent f94e4c55ce
commit 58f1129123
3 changed files with 238 additions and 5 deletions
+1
View File
@@ -2092,6 +2092,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
With Overprint Preview or Separations Preview on, the renderer keeps the art it prepared for the preview from one frame to the next. It prepares again the objects that changed, and all of the art when Discard White Overprint changes or, with Separations Preview, when the plates shown, the proof setup, the swatches, the Spot Colors option or the color settings change or a profile is loaded. It draws the other objects from the art, geometry and stroke outlines it kept for them.
Pathfinder › Merge and the `pathfinder.merge` group effect find the faces of every fill in a few contour passes over the arrangement, as Trim and Crop do, instead of one pass for each distinct fill. The output paths and their order are the same. With 8,000 squares that do not touch, each with its own fill, Merge takes 72 to 107 ms instead of 17 to 32 s (release build).
The Pathfinder panel, Offset Path, Clean Up, Divide Objects Below, Make and Release Blend, Envelope Distort's Make and Release, Repeat (Radial, Grid, Mirror and Release), Vector Halftone, New and Redefine Symbol, Delete Symbol, erasing with the Symbol Sprayer, Rasterize, Convert to Artboards, Flatten Transparency, Clear Guides, Shape Builder, Live Paint, Release Image Trace, Make and Release Opacity Mask, Delete with direct-selected anchor points, Remove Anchor Points, Cut Path, and the Shaper, Knife, Eraser, Path Eraser, Line Cut, Rectangle Cut, Mirror & Cut and Blob Brush tools add and remove objects in one pass over each layer or group they change, and Outline Stroke and Expand write each new object in the place of the object it replaces (#1429).
Cut Path at Selected Anchor Points (`path.cutAtAnchors`) selects the cut ends with one selection call, which skips paths already selected through a hash set, instead of adding each cut path in turn and searching the paths already added. The selection is the same, every field (`selecting_cut_ends_matches_adding_them_one_by_one`). With the 8 middle anchors of each of 5,000 open paths of 10 anchors selected, building the selection of 40,000 cut ends takes 9.7 ms instead of 232 ms of CPU time, and with 2,000 paths 3.2 ms instead of 39 ms; at 500 paths both take 3 ms or less (medians of 7 runs, `cargo run --release -p vectorcraft-engine --example cut_path_select_bench`). Scores and hours unchanged.
Offset Path looks up the segments near each candidate hole or island in a tree of the source path's segment bounds when it decides whether to drop that contour, instead of testing the bounds of every segment. The output paths are the same. On compound and open paths of 25,000 to 40,000 anchors with 6,400 to 11,976 candidate contours, that check takes 11 to 13 ms instead of 140 to 649 ms (medians of five interleaved runs). The limit on overlapping segment pairs is the same, so a path that stops with "Offset Path: the path is too complex to offset" still stops there.
Offset Path on several selected paths, or on a group of them, works out their offsets on as many threads as the computer has logical CPUs (one thread on the web and for a single path), and then makes the new objects one after another in the selection's order. The new objects, their ids, their stacking, the selection and the undo step are the same as when the paths were offset one at a time, and when more than one path fails, the error is the one for the first of them in that order (`tests::pathops::offset_path_of_several_objects_keeps_their_order`, `tests::pathops::offset_path_works_on_several_threads_in_order`, `tests::pathops::offset_path_stops_after_the_first_failure`).
Finding the distinct regions of an arrangement lists the shapes that cover each region instead of keeping a flag for every shape, so that step's time follows how many shapes cover each region rather than how many shapes there are. Divide, Hard Mix, Soft Mix, Shape Builder, Flatten Transparency, trapping, Intertwine and the Pathfinder effects are among the commands that use that step. The regions, their order and the output are the same. Divide on 3,000 overlapping rectangles takes 0.84 to 1.13 billion CPU cycles on its thread instead of 1.25 to 1.46 billion (dev build, six runs of each, alternating, while other builds were running).