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:
committed by
GitHub
parent
ddd65cc4bb
commit
36bdf4ea3c
@@ -932,16 +932,35 @@ impl Session {
|
||||
|
||||
/// Mutable document (copy-on-write).
|
||||
pub fn doc_mut(&mut self) -> &mut Document {
|
||||
// The placement index keeps the document alive with its answers; let it go before an
|
||||
// in-place edit, so the edit stays in place (a shared handle would clone the document
|
||||
// to a new address behind the crash journal's back, #7502) and no stale lookup outlives it.
|
||||
self.forget_document_caches();
|
||||
#[cfg(test)]
|
||||
if Arc::strong_count(&self.doc) > 1 {
|
||||
tests::doc_copies::record();
|
||||
}
|
||||
Arc::make_mut(&mut self.doc)
|
||||
}
|
||||
|
||||
/// Make `doc` the design, as `*doc_mut() = doc` does, without first copying a shared
|
||||
/// document only to overwrite the copy: a command's undo step still holds the design it
|
||||
/// started from, so `doc_mut` would copy all of it (every feature and sketch) on each
|
||||
/// sketch drag frame. The design lands at a new address either way, and the command's end
|
||||
/// tells the crash journal that address (#7502).
|
||||
pub(crate) fn set_doc(&mut self, doc: Document) {
|
||||
self.forget_document_caches();
|
||||
self.doc = Arc::new(doc);
|
||||
}
|
||||
|
||||
/// Before the document changes: the placement index keeps the document alive with its
|
||||
/// answers; let it go, so an in-place edit stays in place (a shared handle would clone the
|
||||
/// document to a new address behind the crash journal's back, #7502) and no stale lookup
|
||||
/// outlives it.
|
||||
fn forget_document_caches(&mut self) {
|
||||
if let Ok(mut index) = self.placement_index_cache.lock() {
|
||||
*index = None;
|
||||
}
|
||||
self.forget_consumed_sketches();
|
||||
self.forget_dirty_answer();
|
||||
self.model.forget_fingerprints();
|
||||
Arc::make_mut(&mut self.doc)
|
||||
}
|
||||
|
||||
/// Prepared placements only: optional save caches must not compute a cold world.
|
||||
|
||||
Reference in New Issue
Block a user