Skip to content

fix: drop the redundant SVG mask so removed elements can be collected - #5208

Open
Arthur031221 wants to merge 1 commit into
google:masterfrom
Arthur031221:fix-remove-svg-mask-leak
Open

Arthur031221 wants to merge 1 commit into
google:masterfrom
Arthur031221:fix-remove-svg-mask-leak

Conversation

@Arthur031221

Copy link
Copy Markdown
Contributor

Reference Issue

Related to #5062.

Description

In Chromium browsers, every <model-viewer> that is removed from the page stays in memory, including its canvas. Pages that swap models in a list or a route (the flow in #5062) grew by about 17 MB per removed 700x500 element at a device pixel ratio of 3.

The interaction prompt icon in each shadow root points a path at a mask with url(#B), and Chromium keeps the shadow tree of such an element alive through its style cache. The mask is a white rectangle around the path's own bounds, so this removes the <defs>, the <mask> and the mask attribute.

Testing

With a WeakRef and --expose-gc, 10 of 10 removed elements stayed alive before and 1 of 10 after. Added a spec in model-viewer-base-spec.ts that the shadow root has no mask, and ran it on Chromium.

Assisted by Claude/Codex.

The interaction prompt icon in every shadow root referenced a mask with url(#B), which makes Chromium keep the shadow tree of a removed element alive.

Signed-off-by: Arthur031221 <124417490+Arthur031221@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant