Skip to content

[diffs] Parse the icon sprite once per document - #1106

Open
mds-ant wants to merge 1 commit into
pierrecomputer:mainfrom
mds-ant:diffs-clone-icon-sprite
Open

[diffs] Parse the icon sprite once per document#1106
mds-ant wants to merge 1 commit into
pierrecomputer:mainfrom
mds-ant:diffs-clone-icon-sprite

Conversation

@mds-ant

@mds-ant mds-ant commented Aug 30, 2026

Copy link
Copy Markdown

Description

createSVGSpriteElement() now parses the markup once per document (kept in a WeakMap, so a fresh jsdom document in tests gets its own copy) and returns a deep clone on each call. On pages that mount many instances, this is cheaper and faster than repeatedly parsing the the SVGSpriteSheet markup.

Motivation & Context

File and FileDiff re-parsed the ~8.5 KB SVGSpriteSheet markup with innerHTML every time an instance mounted its shadow root. On pages with many instances that parse is a noticeable share of mount cost, and it produces the same nodes every time.

Type of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactoring (non-breaking change)
  • New feature (non-breaking change which adds functionality). You must have
    first discussed with the dev team and they should be aware that this PR is
    being opened
  • Breaking change (fix or feature that would change existing functionality).
    You must have first discussed with the dev team and they should be aware
    that this PR is being opened
  • Documentation update

Checklist

  • I have read the contributing guidelines
  • My code follows the code style of the project (moon run root:lint)
  • My code is formatted properly (moon run root:format)
  • I have updated the documentation accordingly (not applicable here)
  • I have added tests to cover my changes (IMO not needed here)
  • All new and existing tests pass (moonx diffs:test)

How was AI used in generating this PR

The code for this performance improvement was written by Claude Code.

…ance

`File` and `FileDiff` re-parsed the ~8.5 KB `SVGSpriteSheet` markup with
`innerHTML` every time an instance mounted its shadow root. On pages with many
instances that parse is a noticeable share of mount cost, and it produces the
same nodes every time.

`createSVGSpriteElement()` now parses the markup once per `document` (kept in
a `WeakMap`, so a fresh jsdom document in tests gets its own copy) and returns
a deep clone on each call. `ensureSpriteSVG` in both components uses it; the
resulting DOM is unchanged. The helper is internal and not exported.
@vercel

vercel Bot commented Aug 30, 2026

Copy link
Copy Markdown

@mds-ant is attempting to deploy a commit to the Pierre Computer Company Team on Vercel.

A member of the Team first needs to authorize it.

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