chore: improve signal performance by reducing duplicate deps

#14945

Pull request

Merged
T
trueadm
Jan 8, 2025, 12:48 AM

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

Info

Merged at Jan 8, 2025, 9:46 AM
Merged by trueadm
Assignees None
Reviewers None
Labels None
Milestone None