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

chore: improve signal performance by reducing duplicate deps #14945

Merged
merged 6 commits into from
Jan 8, 2025

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Jan 8, 2025

This PR introduces read versioning, which is different from write versioning (the existing version naming has been updating to be wv respectfully). When we read a signal in a given reactive context we can provide it a read version. This provides us a benefit in that if we have duplicate reads of the same signal, we avoid populating the same signal many X times in the same reaction's dependencies. This is actually significant in many stress-cases where you might read a[x] in a loop, where a a is a signal. If x is 10000, we end up with 10k of a as a dependency, when only a single is satisfactory.

This optimisation adds an extra field to source and derived signals, which is probably worth while given the real-world implications of having a huge reactive dependency array and reactive graph because of additional re-visits.

In terms of of our reactive benchmark the benefits are clear:

Before:
Screenshot 2025-01-08 at 00 51 05

After:
Screenshot 2025-01-08 at 00 54 18

Copy link

changeset-bot bot commented Jan 8, 2025

🦋 Changeset detected

Latest commit: bca2f22

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 Jan 8, 2025

Playground

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

Copy link
Member

@Rich-Harris Rich-Harris left a comment

Choose a reason for hiding this comment

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

this is ingenious!

I think we should either use write_version and read_version in place of w_version and r_version or, if we're trying to be compact, vw and vr (and rely on Intellisense to explain what they are). Having something in between means we don't really get the benefits of compactness or understandability

packages/svelte/src/internal/client/reactivity/types.d.ts Outdated Show resolved Hide resolved
packages/svelte/src/internal/client/reactivity/types.d.ts Outdated Show resolved Hide resolved
packages/svelte/src/internal/client/dev/tracing.js Outdated Show resolved Hide resolved
packages/svelte/src/internal/client/runtime.js Outdated Show resolved Hide resolved
@Rich-Harris
Copy link
Member

preview: https://svelte-dev-git-preview-svelte-14945-svelte.vercel.app/

this is an automated message

@trueadm trueadm merged commit 9c20eb4 into main Jan 8, 2025
11 checks passed
@trueadm trueadm deleted the read-version branch January 8, 2025 09:46
@github-actions github-actions bot mentioned this pull request Jan 8, 2025
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