You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Did you notice that if you create the deriveds outside of the run function it doesn't re-evaluate this much? Are you sure this is a good reproduction of your solution where you create the derived and immediately update it?
In our case there are many derived values in a DAG across a few different classes, exposed via getters.
It's hard to tell exactly how many times each derived value in the chain is recalculated when a tip value is read a single time because there are many reads all happening within quick succession.
For now we will stick with stores because we really need the reads at the tips to be fast, and when using $derived the full dependency hierarchy is checked for any dirty values which is already too much overhead.
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
https://svelte.dev/playground/hello-world?version=5.30.1#H4sIAAAAAAAAE7XTXWvbMBQG4L9yEIPaVHPXbWXgOIFCy7qLZTDaq2oXsnyciSlHRjrOGoL_-3C8LMnwCAR2Z1751SN_nI0gvUSRizsMdoUVrLRrEQK-Nn7ZtIwV4EvjCYmtdm4tpKitwyjy543gddNX-0DI3Ua3TZPFFTrus1JHHMuNJ0biKHJRRBNswzNFiuuWDFtPEFpKUtj0mWKHDBqm8CqyZkzepJN9XvZ5NZw9K9dJksJ0tisqNp6id5g5v0iUGB7J0gLKLMuU2G2kOCC3geCz5u_Z0lKiJdzsVrtDz5znmRNeKeH9qFed51UnPCPh3aiH53l4wqskvB316v_joYTrUW9xnlePe_URsb2sfYCklyxM4XoCFgr4MAF7eZn-i3lqKr1Vgvc8DGAOSkiwe7D__-1kvH9rDMa4_eyHQ3x43uPC0awP1OLP2_pdob9rF3df5vcXab_QKSqu9mNLRdkyewJPxlnzY7oJLXWzr09zeHy4h8eHT_OPxdVwz0yRkILxhUXOocXumxSsrftpqRJ5rV3E7hewKTmAlAQAAA==
Logs
System Info
Severity
blocking an upgrade
The text was updated successfully, but these errors were encountered: