Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds legacy mode flag #14180

Merged
merged 8 commits into from
Nov 6, 2024
Merged

feat: adds legacy mode flag #14180

merged 8 commits into from
Nov 6, 2024

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Nov 6, 2024

This PR makes it so Svelte components that are in legacy mode mark the legacy mode flag and adds the flag to parts of the codebase that do checks for runes. In practice this means that if all your components are in runes mode, Rollup can strip out all the runtime code that handles legacy mode, reducing bundle code-size and improving runtime performance.

I was expecting bigger wins, but some small gains are better than nothing! Notable wins are inside our props logic and await blocks. Some hot paths are also improved as it means less is_runes lookups.

I also considered adding a DEV time console.info message if you have a component that is in legacy mode to help inform the user, but this might be a bit noisy on reflection so I decided against it.

Copy link

changeset-bot bot commented Nov 6, 2024

🦋 Changeset detected

Latest commit: 8899263

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

Copy link
Contributor

github-actions bot commented Nov 6, 2024

Playground

pnpm add https://pkg.pr.new/svelte@14180

@dummdidumm
Copy link
Member

dummdidumm commented Nov 6, 2024

Nice ! Out of curiousity: how much savings are we talking about (in kb, unminified or minified, I don't care)

@Rich-Harris
Copy link
Member

What if we move src/internal/feature-flags.js to src/internal/flags/index.js and src/internal/legacy-component.js to src/internal/flags/legacy.js? Keeps things a bit more nicely organised and gives us a place to add other things in future

@trueadm
Copy link
Contributor Author

trueadm commented Nov 6, 2024

@dummdidumm It's variable depending on what you use. For a simple component:

<script>
	let x = $state(0);
	let { y = 0 } = $props();
</script>

<button onclick={() => x++}>{x}</button>
{y}

Screenshot 2024-11-06 at 12 34 37

Screenshot 2024-11-06 at 12 35 01

So a 0.3kb saving on a simple component, but still a saving!

@trueadm
Copy link
Contributor Author

trueadm commented Nov 6, 2024

@Rich-Harris Applied your feedback :)

@dummdidumm
Copy link
Member

to not regress, we should add a test similar to the one checking that hydration code is treeshaken out (check-treeshakeability.js)

@trueadm
Copy link
Contributor Author

trueadm commented Nov 6, 2024

@dummdidumm Mind helping me do that? Not sure what we should check for in the code.

@dummdidumm
Copy link
Member

it's not an exact science. Basically you pick a string that shouldn't be present anymore after treeshaking, like component_context.l = {

@trueadm
Copy link
Contributor Author

trueadm commented Nov 6, 2024

@dummdidumm Thanks, done that now

Copy link
Member

@Conduitry Conduitry left a comment

Choose a reason for hiding this comment

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

This changeset needs to be different, IMO. It doesn't describe what's happening to an end user at all. And it should also probably be a fix or chore because there's no visible API changes.

@trueadm
Copy link
Contributor Author

trueadm commented Nov 6, 2024

@Conduitry Is that better?

Copy link
Member

@Conduitry Conduitry left a comment

Choose a reason for hiding this comment

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

Yup sounds good 👍

@trueadm trueadm merged commit f1aeaf1 into main Nov 6, 2024
11 checks passed
@trueadm trueadm deleted the legacy-mode-flag branch November 6, 2024 16:41
@github-actions github-actions bot mentioned this pull request Nov 6, 2024
trueadm added a commit that referenced this pull request Nov 7, 2024
* feat: adds legacy mode flag

* feedback

* feedback and tweaks

* feedback and tweaks

* tweaks

* tweaks

* tweaks

* tweaks
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.

4 participants