Repository navigation
perf(core): a sealed drag restyles only the selection outline pieces that moved - #9092
miguel-heygen wants to merge 3 commits into
Conversation
…that moved On each drag step the sealed frame cleared and rewrote the whole inline style of every node of Studio's selection outline copy, about 450 style writes a frame. The look is now written once when the copy mounts, and each step writes only the place values that changed.
terencecho
left a comment
There was a problem hiding this comment.
P2 — Restore the base longhands when a shorthand override is removed. At packages/core/src/runtime/editing/dragChrome.ts:148, removing an inline inset also clears the mounted look’s left and top. Chrome moved the draft outline to (0, 0) on the next step, while the previous implementation restored the base position. Preserve the fast path for independent properties and rebuild the affected styles when declarations overlap.
Two smaller issues with the performance check. Chrome rounds the serialized plane transform, so comparing it with the raw generated string can still request a style write every step. The MutationObserver test also passes with the per-property write guard removed, because identical assignments can leave the attribute unchanged.
71 targeted tests passed. I verified the shorthand behavior in Chrome. The full edit-accuracy benchmark and compositor performance were unverified locally.
— tai (automated review)
Edit accuracy: accurate 275 (base branch 273), smooth 59 of thoseThe gate passes. Newly passing (2)
Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)
Quarantined, measured but not gated (0) |
… shorthand goes A place value that overlaps others, such as inset, rebuilds the node as before. Only independent values (left, top, width and the like) are written alone, and the plane's transform is compared with what was last written.
|
All three points fixed at
fails without the fix (
Each also fails with one part removed: the value guard or the transform guard fails the first; the dropped-value rebuild or the shorthand rebuild fails the second. Core editing suites: 396 of 396, three runs. Corrections to the measurements in the description:
|
jrusso1020
left a comment
There was a problem hiding this comment.
Reviewed at d39e3ea. Approve.
Read dragChrome.ts and dragChrome.test.ts whole at this head, and frameDragChrome.ts placeOf for what Studio sends as a place. Nothing was run here (no installed dependencies on this box); this is a read of the code.
The open change request, point by point:
- A removed shorthand clearing the look's own values: resolved.
writeMovedPlacenow takes the incremental path only when every name in the last and next place is one of seven properties that do not overlap each other (left,top,width,height,transform,opacity,clip-path). Any dropped name, or a change while another name is present, goes throughwriteNode, which is the old full rewrite (look, place, thenpointer-events). The new test covers both a changed and a droppedinset. - Plane transform compared against the serialized value: resolved. The comparison is against the string the code itself last wrote (
planeAt), reset on clear. - Test passing without the per-property guard: resolved. The test now counts
setPropertycalls and asserts the third identical step adds none.
I also checked the incremental path against the old result: a first step after mount has an empty remembered place, so every value is written over the look in the same order as before; a place that carries pointer-events never takes the incremental path, so the forced none stays last.
Non-blocking:
- The body's
fails without the fix:line names "writes only the place that moved, and puts back the look a place no longer overrides". That test is now two: "writes only the place that moved, counting every style write" and "rewrites a node's look and place when a place shorthand changes or goes". Worth a body edit. - Studio builds a place from the element's inline style names, which are always longhands. A moved outline piece whose inline style carries any name outside the seven (for example
rightorbottom) takes the full rewrite for that piece each step. Correct, just not the fast path; the trace numbers in the body suggest the moved pieces do not hit this today.
Need: yes, measured cost only the sealed preview had · Size: 2 files, +69/-7 · Reuse: writeNode keeps the old rewrite as the fallback · Simpler: no · Structure: fine
Risk: low; the sealed preview is not on by default.
— Rames
What
A drag in a sealed preview no longer restyles the whole selection outline every frame. The frame draws a copy of Studio's selection outline with each drag step, and each step used to clear and rewrite the full inline style of every node of that copy: about 450 style writes per frame for a plain move. Now the copy's look is written once when it mounts, and each step writes only the place values that changed.
Why
Studio may only seal its preview by default once it behaves the same in both modes, with no lag only the sealed preview has. The edit accuracy bench's merge queue run measures both modes: of 751 cases, 247 are smooth unsealed and 104 sealed. A Chrome trace of a failing sealed move showed the frame recalculating style and repainting the whole outline copy on every frame, which the unsealed preview never does: its outline lives in Studio's own page and only the moved values change.
Related work
Follow-up to #9068 (the merge queue's sealed edit accuracy run).
How
dragChrome.ts:buildwrites a node's look andpointer-events: none !importantwhen the copy mounts.writeMovedPlacewrites only the place values that differ from the last step. A place value the next step leaves out falls back to the node's look, or is removed when the look has none, which is what the old full rewrite left. The plane's transform is written only when it changes.nodesagain) clears the remembered places, so its first step writes every place value.Test plan
fails without the fix: "writes only the place that moved, and puts back the look a place no longer overrides" (
packages/core/src/runtime/editing/dragChrome.test.ts) fails with the olddrawDragChrome: a step that moves one node mutates every node's style.dragChrome.test.tsandeditingDraft.test.ts: 34 of 34.packages/core/src/runtime/editing/,editingDraft.test.tsandeditingPort.test.ts: 395 of 395. StudioframeDragChrome.test.ts: 7 of 7.tsc --noEmitinpackages/core: exit 0.Edit accuracy bench, the 30
move-cases of the PR grid, the preview in Studio's process as CI runs it, 3 runs interleaved, on a Linux machine with no GPU. Each build was made from one tree, so they differ only by this change:mainWith the frame in its own process (full Chrome), sealed moves still drop more frames than unsealed after this change: fewer than before, but not as few as unsealed. The rest is the cost of drawing a second process's frame, and is not changed here.
Unit tests added/updated
Manual testing performed
Documentation updated (if applicable)
Comments follow CONTRIBUTING.md "Comments": they say why, not what, and a bug fix says what the code must do and how to reproduce the bug
No visible change
The sealed preview is not on by default. In a sealed preview the outline looks and moves the same; it costs less to draw.