Sketch drag: drop the second document copy per frame (#10507)

* claim: Sketch drag: drop the second document copy per frame

* Sketch drag: drop the second document copy per frame

edit_solved copied the document to edit it, then stored it with
`*s.doc_mut() = doc`. The command's undo snapshot still holds the old
document, so doc_mut copied the whole design a second time only to
overwrite it. Store the edited document with Session::set_doc instead,
which forgets the same caches and puts it in a new Arc. The design lands
at a new address as before and the command's end records it for the
crash journal (#7502).

A live drag frame on a design of 200 sketches (20k curves) drops from
19.2 ms to 9.4 ms; 50 sketches: 2.3 ms to 1.7 ms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Markus Kaltenbrunner <kaltenbrunnermarkus@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
kaltenbrunnermarkus
2026-11-01 10:13:17 +00:00
committed by GitHub
parent ddd65cc4bb
commit 36bdf4ea3c
6 changed files with 164 additions and 5 deletions
+18
View File
@@ -6,6 +6,24 @@ use crate::*;
mod mesh_convert;
/// Counts the copies `Session::doc_mut` makes of a shared document.
pub(crate) mod doc_copies {
use std::cell::Cell;
thread_local! {
static COUNT: Cell<usize> = const { Cell::new(0) };
}
pub fn record() {
COUNT.with(|c| c.set(c.get() + 1));
}
/// The count since the last call.
pub fn take() -> usize {
COUNT.with(|c| c.replace(0))
}
}
fn run(s: &mut Session, id: &str, p: Value) -> Value {
match s.execute(id, &p) {
Ok(v) => v,