From ce614044a73e17eebdc9506f3897538731590a2d Mon Sep 17 00:00:00 2001 From: semmelrinde <124386289+semmelrinde@users.noreply.github.com> Date: Sun, 25 Oct 2026 01:55:29 +0000 Subject: [PATCH] Evaluation: a feature's fingerprint text is written only when the feature changed (#6397) Every evaluation fingerprints every feature by its JSON, so a design built command by command wrote all of its features out as JSON on every command. The text is now kept (per thread, by feature id) with the feature it was written from, and written again only when the feature differs; the text hashed is the same, so the fingerprints are too. Imports, whose text depends on their STEP digest, are written each time as before. Co-authored-by: Claude Opus 5.5 --- crates/doc/src/eval.rs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/crates/doc/src/eval.rs b/crates/doc/src/eval.rs index c951844d5..f27a28b9b 100644 --- a/crates/doc/src/eval.rs +++ b/crates/doc/src/eval.rs @@ -1155,7 +1155,7 @@ fn fingerprint(prev: u64, f: &Feature, vals: &BTreeMap, rolled_ba prev.hash(&mut h); rolled_back.hash(&mut h); vals.get(DESIGN_LEN).map(|v| v.v.to_bits()).hash(&mut h); - feature_json(f, steps).hash(&mut h); + hash_feature_json(f, steps, &mut h); for n in param_names(f) { n.hash(&mut h); match vals.get(&n) { @@ -1234,6 +1234,36 @@ fn quantize(sk: &mut solidcraft_sketch::Sketch) { /// A feature as fingerprinted: its definition, a sketch's stored solve quantized, an imported /// file's text by its digest. +/// Hash [`feature_json`] of `f` into `h`. Every evaluation fingerprints every feature, and in a +/// design built command by command almost all of them are the same as last time: the text of a +/// feature is kept (per thread, by id) with the feature it was written from, and written again +/// only when the feature differs. An Import's text also depends on its STEP digest, so it is +/// written each time as before. +fn hash_feature_json(f: &Feature, steps: &StepDigests, h: &mut impl Hasher) { + if matches!(f.kind, FeatureKind::Import { .. }) { + feature_json(f, steps).hash(h); + return; + } + thread_local! { + static WRITTEN: std::cell::RefCell> = std::cell::RefCell::new(std::collections::HashMap::new()); + } + WRITTEN.with(|written| { + let mut written = written.borrow_mut(); + if let Some((seen, json)) = written.get(&f.id) + && seen == f + { + json.hash(h); + return; + } + let json = feature_json(f, steps); + json.hash(h); + if written.len() >= 1 << 15 { + written.clear(); + } + written.insert(f.id, (f.clone(), json)); + }); +} + fn feature_json(f: &Feature, steps: &StepDigests) -> String { if let FeatureKind::Import { step, .. } = &f.kind { let mut g = f.clone();