🐛 Skip numerically equal component sync writes

Compare integer and floating forms exactly for scalar values, points and
selection rectangles. A library update that only changes their numeric
representation must not create changes or an undo entry. Preserve every
nonzero difference, including real subpixel moves.

Add the reduced resize/library-sync regression and a subpixel control,
plus async frontend undo/redo replay. Review and update eight golden
states in case N: only equal integer/float representations changed.
The recreated seed-712 audit leaves all 61 syncs and undo depths unchanged.

Common JVM 1,914 tests/31,146 assertions and JS 1,845/29,810 pass.
Frontend 1,563/10,880, its added replay, backend 1,610/8,104 and exporter
14/32 pass. Lint and formatting pass. Exporter needs its test-only secret.

Benchmark ratios against the unchanged baseline: mains 10/100/1000
0.54/0.61/0.61, levels 0.53, chain 0.55, library 0.55, many shapes 0.62,
variant switch 0.65. No regression flag.

AI-assisted-by: gpt-6
This commit is contained in:
alonso.torres 2026-10-27 13:24:06 +01:00
parent e5dc24ed83
commit f54d1a288e
4 changed files with 47 additions and 2 deletions

View File

@ -1330,6 +1330,24 @@
(or (automatic-name content) origin-name))
origin-name)))
(defn- same-sync-value?
"Compare numeric values exactly, including integer/float representations
inside geometry. Every nonzero difference still requires a sync."
[attr value other]
(or (= value other)
(let [same-number? (fn [a b] (and (number? a) (number? b) (== a b)))]
(case attr
:selrect (and (map? value) (map? other)
(= (set (keys value)) (set (keys other)))
(every? #(same-number? (get value %) (get other %)) (keys value)))
:points (and (sequential? value) (sequential? other)
(= (count value) (count other))
(every? (fn [[a b]]
(and (same-number? (:x a) (:x b))
(same-number? (:y a) (:y b))))
(map vector value other)))
(same-number? value other)))))
(defn- sync-attr-operations
"The `[attr value]` pairs that sync `attr` from `origin-shape`, a main
shape placed like `dest-shape`, into `dest-shape`, its copy. With
@ -1370,7 +1388,7 @@
skip?
(or (and (not text-name?)
(= (get origin-shape attr) (get dest-shape attr)))
(same-sync-value? attr (get origin-shape attr) (get dest-shape attr)))
(and (touched sync-group)
omit-touched?
;; When it is a text-partial-change, we should generate operations
@ -1399,7 +1417,7 @@
(cond
;; If the final attr-value is the actual value, skip
(or skip? (= attr-val (get dest-shape attr)))
(or skip? (same-sync-value? attr attr-val (get dest-shape attr)))
[]
;; On a text-partial-change, we want to force a position-data reset

View File

@ -33,6 +33,21 @@
(t/use-fixtures :each thi/test-fixture)
(t/deftest sync-keeps-a-real-subpixel-position-change
(let [initial (setup/simple-component-with-labeled-copy)
original (tm/resolve-shape initial :copy-child)
file (tm/file initial)
page (thf/current-page file)
changes (cls/generate-update-shapes
(pcb/empty-changes nil (:id page)) [(thi/id :main-child)]
#(gsh/move % (gpt/point 0.000001 0)) (:objects page) {})
source (thf/apply-changes file changes)
changed (tm/with-file initial (:file (r/sync-cascade source {} (keys (get-in file [:data :components])))))
actual (tm/resolve-shape changed :copy-child)
expected (gsh/move original (gpt/point 0.000001 0))]
(t/is (not= (:points original) (:points actual)))
(t/is (gsh/close-attrs? :points (:points expected) (:points actual) 1e-10))))
(t/deftest grid-sync-keeps-new-main-cells
(let [file (-> (thf/sample-file :file1)
(tho/add-grid-frame :main-root :width 100 :height 100)

View File

@ -382,6 +382,13 @@
(t/is (= {} (get-in result [:result-text :content-group])))
(t/is (false? (shadow/same-value? (:result-text after) :text-content-size expected)))))))
(t/deftest accepting-a-library-does-not-record-equal-numeric-geometry
(let [before (-> (cg/initial-state [2 1 {:library true :variants true}])
(cg/step [:resize 10 2 2 10]) cg/settle-state)
after (-> before (cg/step [:library-sync 3 1 2 8]) cg/settle-state)]
(t/is (= (r/undo-depth (:situation before)) (r/undo-depth (:situation after))))
(t/is (= (oracle/snapshot (:situation before)) (oracle/snapshot (:situation after))))))
(t/deftest source-library-edits-wait-for-explicit-consumer-acceptance
(let [initial (cg/initial-state [2 1 {:library true :stale-libraries true}])
situation (:situation initial)

View File

@ -128,6 +128,11 @@
(t/is false (str (ex-message error) "\nReplay: " (pr-str program)
"\nDetails: " (pr-str (ex-data error)))))))
(t/deftest ^:async accepting-a-library-does-not-record-equal-numeric-geometry
(await (replay {:world [2 1 {:library true :variants true}]
:ops [[:resize 10 2 2 10] [:library-sync 3 1 2 8]
[:undo] [:redo]]})))
(t/deftest ^:async nesting-a-swapped-copy-in-a-blocked-main-authors-its-lock
(await (replay {:world [2 0 {:library true :variants true :rich-variants true
:text true :text-styles true :layout nil :layout-copies true}]