Skip to content

Undo of a large erase: the resident wire patch tells that it has to decline before it tessellates the objects - #3471

Merged
HakanSeven12 merged 2 commits into
HakanSeven12:mainfrom
jespinolao:perf/resident-patch-declines-early
Nov 23, 2026
Merged

HakanSeven12 merged 2 commits into
HakanSeven12:mainfrom
jespinolao:perf/resident-patch-declines-early

Conversation

@jespinolao

Copy link
Copy Markdown
Contributor

How it shows up

Refs #3231 ("lag ... at times more than a few seconds" when working on groups in large files). There is no file there, so this is a synthetic drawing of 100,800 objects (14,400 cells of five lines, a circle and a text). Select the 100,440 in view, ERASE, then Undo: the objects take 3 seconds to come back. Six tenths of a second of that are a patch of the resident wire set that does not go in:

[perf] resident-patch-skip reason=new-run-not-at-the-tail
[perf] resident-patch-attempt 584.2ms hit=false
[perf] wires-build total=136.4ms ... tess=110.5 ... memo_hit=360 memo_miss=100440

Cause

Erasing more than half of the set has it built again without the erased entities (too-many-tombstones). The undo then brings them back as entities the set has no slots for, between the 360 that stayed. A new run only goes in at the tail, so try_resident_patch declines and the full build takes over.

It found that out when it placed the first new run, which is after it had looked up and tessellated all 100,440 entities and copied their runs for the GPU patch. The full build then tessellates them again: their memo entries are pending ones, which count as a miss.

The change (src/scene/resident_wires.rs)

Before it looks up and tessellates the changed entities, the patch now asks whether one of the new ones is bound to decline it:

  • It finds the last run in the order that the patch leaves alone: an entity that is not among the changes and holds a run.
  • A new entity that the order update will list before that run cannot go in at the tail. Its place is worked out the way the order update does it, by its sort key. The usual add, whose key comes after every listed one, is passed over with one comparison.
  • Such an entity declines the patch unless it is hidden or draws nothing, so it is checked for visibility and tessellated, that one entity alone. If it draws, the patch declines with the reason it gave before, new-run-not-at-the-tail.
  • Up to four candidates are looked at (DECLINE_PROBES); after that the patch goes on as it did, and still declines at the placement if it has to.
  • tessellate_entity is called through one closure by this check and by the parallel pass.
  • Scene::resident_patch_tessellated counts the entities a patch tessellates, next to resident_patch_hits, for the test.

What the patch does when it goes in is unchanged, and so is the set the full build makes after a declined one.

Measured

Release builds, Windows 11, RTX 3070, Direct3D 12, PERF=1. main is 0ca0345 with the lock file of #3459 so that it builds. "Frame" is nav-prepare elapsed, from the command to the prepared frame. Two runs of each build.

main This PR
Undo of an ERASE of 100,440 objects: frame 3,054 / 3,001 ms 2,451 / 2,471 ms
— resident-patch-attempt, declined 611.9 / 600.2 ms 4.1 / 3.8 ms
— the full build after it (wires-build) 151.0 / 138.3 ms 148.9 / 150.9 ms
COPY of 100,440, patched in: resident-patch-attempt 293.9 / 280.0 ms 292.4 / 295.7 ms
Undo of an ERASE of 33,480, patched in: resident-patch-attempt 86.0 / 80.3 ms 80.3 / 81.2 ms

The last two rows are patches that go in: the check adds nothing that shows.

The same view captured after each step of a sequence in both builds (MOVE of everything, its undo, ERASE of everything, its undo, MOVE of scattered objects, its undo: 11 captures). The drawing is the same pixel for pixel in all of them; one capture has the pointer's crosshair over the canvas in one build and not in the other.

After the undo of the ERASE, main This PR
main: the drawing back after the undo this PR: the same image

Tests (src/scene/resident_patch_adds_tests.rs)

  • a_patch_that_cannot_place_its_new_entities_declines_before_tessellating_them: 400 lines, all but each tenth erased (the set is built again with the 40 that stay) and restored. The patch must not go in, must tessellate at most four entities, and the set must draw the whole drawing again. Fails on the first commit: the declined patch tessellated 360 of the 360 entities before the full build.
  • The test and the counter are the first commit; the change is the second.
  • cargo test --lib scene::resident_patch_adds_tests scene::journal_tests: 41 passed.
  • cargo test --workspace --no-fail-fast, with the lock file of Cargo.lock: gpu-allocator is back on the windows crate wgpu-hal uses, so main builds on Windows #3459: 7,755 passed, 2 failed, 49 ignored. Neither failure is about this change:
    • app::control::spellcheck::tests::speller_survives_com_unload_reload_cycles fails the same way on main on this machine;
    • app::command_driver::tests::bedit_characterization_tests::picklocked_off_makes_locked_layer_objects_unselectable passes alone, three runs of three, and its module passes, 16 of 16. It reads PICK_LOCKED, one flag for the process, while other tests set it; it failed the same way in a whole run of main with that lock file (see Cargo.lock: gpu-allocator is back on the windows crate wgpu-hal uses, so main builds on Windows #3459).
  • cargo check --target wasm32-unknown-unknown --lib passes.

Limits

OCS main at 0ca0345, Windows 11.

🤖 Generated with Claude Code

jespinolao and others added 2 commits November 22, 2026 16:33
Erasing most of a drawing has the resident set built again without the
erased entities. Undoing the erase then brings them back as new
entities between the ones that stayed; new runs only go in at the tail,
so the patch declines. The test asks for it to tell before it
tessellates them, since the full build tessellates them again.

`resident_patch_tessellated` counts the entities a patch tessellates.
The patch tessellates all 360 before it declines: the test fails.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Undoing an erase of 100,000 objects spent 0.6 s in a patch of the
resident wire set that then declined. Erasing that much has the set
built again without the erased entities, so the undo brings them back
as new entities between the ones that stayed. A new run only goes in at
the tail, and the patch found that out when it placed the first of
them: after it had looked up and tessellated all of them and copied
their runs. The full build then tessellated them again.

Before that work the patch now looks for a new entity that the order
update will list before a run the patch leaves alone. Such an entity
declines the patch unless it is hidden or draws nothing, so that one
entity is tessellated to tell. Up to four candidates are looked at;
after that the patch goes on as before. The usual add, whose key comes
after every listed one, is passed over with one comparison.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@HakanSeven12
HakanSeven12 merged commit 83b632b into HakanSeven12:main Nov 23, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants