You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
clip does not reduce clone cost for small clipped captures #525
Environment: @zumer/snapdom 3.3.3, Chrome 155, macOS, device pixel ratio 2, production React build, CPU throttled to 6×. Options: clip set to a page rect, reconcile: true, embedFonts: false, outerShadows: false.
One capture run, from the same element tree:
Capture
Clone preparation
Tags in serialized SVG
Full root (410,400 CSS px)
56.9–64.8 ms
80–81
Clipped region (17,100 CSS px)
55.6–67.0 ms
70–71
The docs say offscreen subtrees are pruned before styling and inlining. Here the clipped capture serializes 10 fewer tags and takes the same time to clone. Is pruning expected in this case? Does it depend on the viewport rather than the clip rect?
We also tried excludeStyleProps on non-rendering properties. Clone time did not change beyond the noise of one trial.
Related: #507 describes clone cost from subtrees that do not contribute to the capture.
Limit: this is not yet a standalone repro. The numbers come from a larger app. A minimal repro is the next step before we treat this as a bug.
Thanks for the detailed numbers! The clip keeps a fixed 200px safety margin on every side, so shadows, outlines and blur from elements just outside the clip don't disappear from the capture.
With your sizes, that margin makes the clipped area almost as big as the whole root, so very little gets pruned.
A small demo of your case would really help: we could use it to test how far that margin can shrink without losing anything.
Thanks for the pointer to the margin. Reading the snapDOM 3.3.3 source, clip pruning keeps any box within 200 px of the clip ($n = 200). A subtree beyond that band keeps its outer element and loses its children.
That explains the demo. Its 410×400 root sits entirely inside the margin, so nothing is pruned.
In a larger root, 760×540 with a 332×39 clip, the same rule removes 24 elements at 1280×900, 63 at 800×600 and 69 at 1920×1400. A geometry model of the rule matches those counts within 5 elements.
Can the margin be configurable? If it can, we can test smaller values against our own capture.
Currently it isn't configurable but certainly I can work on that trying to detect a "smart" way to determine the margin automatically. If you want you can even set it to 0 manually modifying the source. If this helps to increase the speed tell me so I can work on the smart way
The 200px margin is now only a ceiling: each element near the clip is kept only if its own shadows, outlines or filters can actually reach the window.
You can try it with npm i @zumer/snapdom@dev (or @3.3.6-dev.0). If anything that should show up in the clip goes missing, a screenshot of that case would help a lot.
Tested 3.3.6-dev.0 on our page. It keeps the same elements as 3.3.3: 137 of 161 for a 332×39 clip. With a margin of 0, the same clip keeps 38.
The cause is Tailwind v4's preflight, which has rules like *, ::after, ::before, ::backdrop, ::file-selector-button { box-sizing: border-box; ... }. Every element matches those pseudo-element gates, so the reach check returns the full 200 px for every element. With those rules removed from the page, the same clip kept 76 elements. The rules set no content, so they create no visible pseudo-elements.
On 3.3.3, a margin of 0 gave identical pixels for this clip at three viewport sizes. Median capture time over 30 interleaved trials:
CPU throttle
margin 200
margin 0
none
17–18 ms
14 ms
4x
50–67 ms
19–25 ms
So pruning does speed up our captures once the elements are actually pruned.
Ran a reach test on 3.3.6-dev.0 and 3.3.3. It covers nine cases where an element outside the clip paints into it: box-shadow spread and offset, outline with offset, filter drop-shadow, text-shadow, an ancestor's drop-shadow, ::after, -webkit-box-reflect, and an absolutely positioned child. All nine render the same clipped as unclipped on both versions. A control with no effect, 70 px from the clip, is pruned on dev and kept on 3.3.3, so the new reach check is active.
One case goes missing on both versions: box-shadow: 0 0 0 400px on an element 370 px from the clip. The shadow paints into the clip in the unclipped capture and is absent from the clipped one, because the element is beyond the 200 px ceiling.
Good catch on the Tailwind preflight, thanks. The check now only keeps the full margin when a ::before/::after actually renders, so rules like *, ::before, ::after { box-sizing: border-box } no longer block pruning (d14b2bd). Could you try @zumer/[email protected] on your page?
The 400px box-shadow case is a known limit for now: anything beyond 200px from the clip is still dropped.
Tried 3.3.6-dev.1 on our page. The Tailwind fix works: for the same 332×39 clip at 1280×900, it keeps 76 elements instead of 137. The output matches 3.3.3 pixel for pixel at three viewport sizes.
Median capture time over 30 interleaved trials:
Viewport
CPU throttle
Elements kept, 3.3.3 → dev.1
3.3.3
3.3.6-dev.1
1280×900
none
137 → 76
18.5 ms
17.8 ms
1280×900
4x
137 → 76
76 ms
53 ms
1920×1400
4x
92 → 43
53 ms
36 ms
800×600
4x
98 → 43
59 ms
36 ms
Without throttling, the difference is within noise. With 4x throttling, dev.1 is 30–40% faster. dev.0, which kept the same 137 elements as 3.3.3, was no faster, so the gain comes from pruning. The host was busier than during my earlier run, so absolute times are higher than in that comment.
The reach test gives the same results on dev.1 as on dev.0.
A correction to my earlier comment: margin 0 on 3.3.3 did not give identical pixels. Our diff compared only the alpha channel. The difference comes from our own font embedding, not snapDOM. It chooses fonts from the text nodes left in the clone, and at margin 0 none were left, so the clip's text field rendered in a fallback font. The margin 0 timings are not a valid baseline.
On 3.3.6-dev.1, reconcile: true costs much less than the 2x you mentioned, at least on this clip. At 4x CPU throttling, reconcile: false was 6–9% faster, or 3–7 ms. Without throttling it was about 1 ms faster, but only when the reconcile: true capture ran first in a pair, so I don't count that.
Same clip, three viewports, 30 trials per setting, alternating which setting ran first. Times are medians:
Viewport
CPU throttle
reconcile: true
reconcile: false
Paired difference, 95% interval
1280×900
none
17.2 ms
16.3 ms
−1.0 ms (−1.7 to −0.1)
1920×1400
none
17.2 ms
16.5 ms
−1.4 ms (−2.0 to −0.5)
800×600
none
17.0 ms
16.5 ms
−0.7 ms (−1.7 to −0.1)
1280×900
4x
76.8 ms
70.0 ms
−7.2 ms (−9.7 to −3.5)
1920×1400
4x
51.3 ms
47.4 ms
−3.8 ms (−5.2 to −2.7)
800×600
4x
51.3 ms
48.2 ms
−3.1 ms (−4.4 to −2.0)
Each time covers our whole capture call, including decoding the SVG into an image, so snapDOM's own share of the difference is larger than these percentages. Both settings kept the same elements: 76, 43 and 43.
At 4x, these times are 33–46% higher than the dev.1 times in my previous comment, with the same element counts. I haven't found the cause, so compare only within this table.
The output barely changes. The clipped capture differs in 2 of 12,948 pixels, each by 1 level out of 255. Full captures of the same root match in five rows, and in the sixth, 472 pixels differ by 1 level. That is one capture per setting per row, in Chrome at dpr 1. Without reconcile, every capture raised reconcile-risk, but I saw no re-wrapping on this page.
These runs pass clip and invalidate: true, so they don't exercise the retained-clone reuse that reconcile: false allows. Our captures would skip that path with either setting, because two of our plugins use afterClone and our font plugin sets fontsCSS.
The original clipping issue appears to be resolved in dev.1, with significantly better pruning, a 30–40% speedup under CPU throttling, and identical visual output.
Regarding reconcile, its impact depends on the DOM structure and capture pipeline, so the results on your application are useful but not necessarily representative of other workloads.
I would consider the original issue fixed and include the improvement in the next stable release. Thanks again for helping validate it!
Your project is super interesting! And thanks for your kind words!
I really believe HTML-in-Canvas is the future. SnapDOM already has a second engine built around this technology, which could eventually eliminate the need for while preserving SnapDOM’s DOM manipulation capabilities and hooks.
In fact, I’m also contributing to the HTML-in-Canvas specification discussions!
Activity
tinchox5 commentedon Oct 17, 2026
@petekp thank you! let me check this issue, jus I need to finish some docs site imprivements before
tinchox5 commentedon Oct 17, 2026
Thanks for the detailed numbers! The clip keeps a fixed 200px safety margin on every side, so shadows, outlines and blur from elements just outside the clip don't disappear from the capture.
With your sizes, that margin makes the clipped area almost as big as the whole root, so very little gets pruned.
A small demo of your case would really help: we could use it to test how far that margin can shrink without losing anything.
petekp commentedon Oct 18, 2026
Thanks for the pointer to the margin. Reading the snapDOM 3.3.3 source, clip pruning keeps any box within 200 px of the clip (
$n = 200). A subtree beyond that band keeps its outer element and loses its children.That explains the demo. Its 410×400 root sits entirely inside the margin, so nothing is pruned.
In a larger root, 760×540 with a 332×39 clip, the same rule removes 24 elements at 1280×900, 63 at 800×600 and 69 at 1920×1400. A geometry model of the rule matches those counts within 5 elements.
Can the margin be configurable? If it can, we can test smaller values against our own capture.
Written by Claude
tinchox5 commentedon Oct 18, 2026
Currently it isn't configurable but certainly I can work on that trying to detect a "smart" way to determine the margin automatically. If you want you can even set it to 0 manually modifying the source. If this helps to increase the speed tell me so I can work on the smart way
Add ink-aware clip culling tests (#525) and improve ink reach logic i…
tinchox5 commentedon Oct 18, 2026
The 200px margin is now only a ceiling: each element near the clip is kept only if its own shadows, outlines or filters can actually reach the window.
You can try it with
npm i @zumer/snapdom@dev(or @3.3.6-dev.0). If anything that should show up in the clip goes missing, a screenshot of that case would help a lot.tinchox5 commentedon Oct 18, 2026
And try capturing with
reconcile: falsebecause unless is needed for fidelity, the speed is downgrade by 2xpetekp commentedon Oct 18, 2026
Tested 3.3.6-dev.0 on our page. It keeps the same elements as 3.3.3: 137 of 161 for a 332×39 clip. With a margin of 0, the same clip keeps 38.
The cause is Tailwind v4's preflight, which has rules like
*, ::after, ::before, ::backdrop, ::file-selector-button { box-sizing: border-box; ... }. Every element matches those pseudo-element gates, so the reach check returns the full 200 px for every element. With those rules removed from the page, the same clip kept 76 elements. The rules set nocontent, so they create no visible pseudo-elements.On 3.3.3, a margin of 0 gave identical pixels for this clip at three viewport sizes. Median capture time over 30 interleaved trials:
So pruning does speed up our captures once the elements are actually pruned.
Written by Claude
petekp commentedon Oct 18, 2026
Ran a reach test on 3.3.6-dev.0 and 3.3.3. It covers nine cases where an element outside the clip paints into it: box-shadow spread and offset, outline with offset, filter drop-shadow, text-shadow, an ancestor's drop-shadow,
::after,-webkit-box-reflect, and an absolutely positioned child. All nine render the same clipped as unclipped on both versions. A control with no effect, 70 px from the clip, is pruned on dev and kept on 3.3.3, so the new reach check is active.One case goes missing on both versions:
box-shadow: 0 0 0 400pxon an element 370 px from the clip. The shadow paints into the clip in the unclipped capture and is absent from the clipped one, because the element is beyond the 200 px ceiling.Written by Claude
tinchox5 commentedon Oct 18, 2026
Good catch on the Tailwind preflight, thanks. The check now only keeps the full margin when a
::before/::afteractually renders, so rules like*, ::before, ::after { box-sizing: border-box }no longer block pruning (d14b2bd). Could you try@zumer/[email protected]on your page?The 400px box-shadow case is a known limit for now: anything beyond 200px from the clip is still dropped.
petekp commentedon Oct 18, 2026
Tried 3.3.6-dev.1 on our page. The Tailwind fix works: for the same 332×39 clip at 1280×900, it keeps 76 elements instead of 137. The output matches 3.3.3 pixel for pixel at three viewport sizes.
Median capture time over 30 interleaved trials:
Without throttling, the difference is within noise. With 4x throttling, dev.1 is 30–40% faster. dev.0, which kept the same 137 elements as 3.3.3, was no faster, so the gain comes from pruning. The host was busier than during my earlier run, so absolute times are higher than in that comment.
The reach test gives the same results on dev.1 as on dev.0.
A correction to my earlier comment: margin 0 on 3.3.3 did not give identical pixels. Our diff compared only the alpha channel. The difference comes from our own font embedding, not snapDOM. It chooses fonts from the text nodes left in the clone, and at margin 0 none were left, so the clip's text field rendered in a fallback font. The margin 0 timings are not a valid baseline.
Written by Claude
tinchox5 commentedon Oct 18, 2026
Great! And did you tried without reconcile:true?
petekp commentedon Oct 19, 2026
On 3.3.6-dev.1,
reconcile: truecosts much less than the 2x you mentioned, at least on this clip. At 4x CPU throttling,reconcile: falsewas 6–9% faster, or 3–7 ms. Without throttling it was about 1 ms faster, but only when thereconcile: truecapture ran first in a pair, so I don't count that.Same clip, three viewports, 30 trials per setting, alternating which setting ran first. Times are medians:
reconcile: truereconcile: falseEach time covers our whole capture call, including decoding the SVG into an image, so snapDOM's own share of the difference is larger than these percentages. Both settings kept the same elements: 76, 43 and 43.
At 4x, these times are 33–46% higher than the dev.1 times in my previous comment, with the same element counts. I haven't found the cause, so compare only within this table.
The output barely changes. The clipped capture differs in 2 of 12,948 pixels, each by 1 level out of 255. Full captures of the same root match in five rows, and in the sixth, 472 pixels differ by 1 level. That is one capture per setting per row, in Chrome at dpr 1. Without
reconcile, every capture raisedreconcile-risk, but I saw no re-wrapping on this page.These runs pass
clipandinvalidate: true, so they don't exercise the retained-clone reuse thatreconcile: falseallows. Our captures would skip that path with either setting, because two of our plugins useafterCloneand our font plugin setsfontsCSS.Written by Claude
tinchox5 commentedon Oct 19, 2026
The original clipping issue appears to be resolved in dev.1, with significantly better pruning, a 30–40% speedup under CPU throttling, and identical visual output.
Regarding reconcile, its impact depends on the DOM structure and capture pipeline, so the results on your application are useful but not necessarily representative of other workloads.
I would consider the original issue fixed and include the improvement in the next stable release. Thanks again for helping validate it!
petekp commentedon Oct 19, 2026
@tinchox5 Happy to help. This library is so awesome, thank you for creating and maintaining it. I've been working on this project (https://munari.vercel.app) for awhile now under the assumption it would require the new, still-in-trial html-in-canvas API. Now it works with or without it 🙌
tinchox5 commentedon Oct 19, 2026
Your project is super interesting! And thanks for your kind words!
I really believe HTML-in-Canvas is the future. SnapDOM already has a second engine built around this technology, which could eventually eliminate the need for while preserving SnapDOM’s DOM manipulation capabilities and hooks.
In fact, I’m also contributing to the HTML-in-Canvas specification discussions!
WICG/html-in-canvas#81
And here’s SnapDOM’s original experiment:
#172
tinchox5 commentedon Oct 19, 2026
https://github.com/zumerlab/snapdom/releases/tag/v3.3.6
docs(core): keep the #525 numbers and name ::slotted() in the scroll …