Skip to content

perf: deduplicate identical hoisted templates within a component#18320

Merged
Rich-Harris merged 3 commits into
sveltejs:mainfrom
MathiasWP:perf/dedupe-hoisted-templates
May 29, 2026
Merged

perf: deduplicate identical hoisted templates within a component#18320
Rich-Harris merged 3 commits into
sveltejs:mainfrom
MathiasWP:perf/dedupe-hoisted-templates

Conversation

@MathiasWP

Copy link
Copy Markdown
Contributor

Byte-identical templates hoisted from different fragments, elements, or branches now share a single $.from_html factory instead of each emitting its own module-scope variable - this shrinks generated output and avoids redundant runtime template parsing. Dedup is keyed on (content, flags) and is skipped in dev mode (templates there are wrapped in $.add_locations, which embeds per-call-site info).

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

Byte-identical templates hoisted from different fragments/elements/branches
now share a single `$.from_html` factory instead of each emitting its own
module-scope variable. Reduces generated code size and avoids redundant
runtime template parsing. Dedup is keyed on `(content, flags)` and skipped
in dev mode (where templates are wrapped in `$.add_locations`).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented May 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4faf241

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Rich-Harris Rich-Harris left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!

@Rich-Harris Rich-Harris merged commit 2fae91a into sveltejs:main May 29, 2026
16 of 17 checks passed
@github-actions github-actions Bot mentioned this pull request May 29, 2026
Rich-Harris pushed a commit that referenced this pull request May 29, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## svelte@5.56.0

### Minor Changes

- feat: allow declarations in the template
([#18282](#18282))

### Patch Changes

- perf: use `createElement` instead of `createElementNS` for HTML
elements ([#18262](#18262))

- perf: store `current_sources` as a `Set` for O(1) membership checks
([#18278](#18278))

- perf: deduplicate identical hoisted templates within a component
([#18320](#18320))

- perf: hoist `rest_props` exclude list as a module-scope `Set`
([#18252](#18252))

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

2 participants