-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Conversation
🦋 Changeset detectedLatest commit: bca2f22 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
There was a problem hiding this 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
preview: https://svelte-dev-git-preview-svelte-14945-svelte.vercel.app/ this is an automated message |
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 reada[x]
in a loop, where aa
is a signal. Ifx
is10000
, we end up with 10k ofa
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:
After: