Open
Description
Describe the bug
Hey!
We are building an app where we have recently been switching from Svelte stores to using Svelte5 $state
and $derived
values, but having done so we are encountering huge performance issues.
I raised #15934 last night, but having debugged further into the issue I have noticed that the stores are being recomputed vastly more than I'd have expected them to be.
Turns out that if you have a chain of derived values, where each derived value's dependency has updated but without causing the dependent value to change, then when you access the top of the chain the number of re-computations increases exponentially with the length of the chain.
Reproduction
Logs
Updating root value: 1
Accessing derived value
computing f...
computing e...
computing e...
computing d...
computing c...
computing b...
Derived value: 1
Updating root value: 2
Accessing derived value
computing b...
computing c...
computing d...
computing e...
computing e...
Derived value: 1
Updating root value: 3
Accessing derived value
computing b...
computing c...
computing d...
computing e...
computing e...
computing e...
Derived value: 1
Updating root value: 4
Accessing derived value
computing b...
computing c...
computing d...
computing e...
computing d...
computing e...
computing d...
computing e...
computing d...
Derived value: 1
Updating root value: 5
Accessing derived value
computing b...
computing c...
computing d...
computing c...
computing e...
computing c...
computing d...
computing c...
computing e...
computing c...
computing d...
computing c...
computing e...
computing c...
computing d...
computing c...
Derived value: 1
Updating root value: 6
Accessing derived value
computing b...
computing c...
computing b...
computing d...
computing b...
computing c...
computing b...
computing e...
computing b...
computing c...
computing b...
computing d...
computing b...
computing c...
computing b...
computing e...
computing b...
computing c...
computing b...
computing d...
computing b...
computing c...
computing b...
computing e...
computing b...
computing c...
computing b...
computing d...
computing b...
computing c...
computing b...
Derived value: 1
DONE
System Info
System:
OS: macOS 15.4.1
CPU: (14) arm64 Apple M3 Max
Memory: 1.02 GB / 36.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.17.0 - ~/.nvm/versions/node/v20.17.0/bin/node
Yarn: 1.22.22 - /opt/homebrew/bin/yarn
npm: 10.8.2 - ~/.nvm/versions/node/v20.17.0/bin/npm
Browsers:
Chrome: 136.0.7103.114
Safari: 18.4
Severity
blocking an upgrade
Metadata
Metadata
Assignees
Labels
No labels