Skip to content

$derived value re-computed each time it is read even if no dependencies have changed #15934

@hpeebles

Description

@hpeebles

Describe the bug

This is more of an annoyance than a bug since the correct value ends up being returned, but unnecessary computation takes place (which in my use case is causing significant performance degradations).

The issue occurs when a unowned derived value depends on some state, then that state is updated, but the derived value evaluates to the same thing based on the new state. From this point on the derived value is always flagged as MAYBE_DIRTY and so is re-computed each time it is read.

Reproduction

https://svelte.dev/playground/hello-world?version=5.30.1#H4sIAAAAAAAAE7VSTU_jMBD9K6MRUlMpBMrRpJWQQMteirQLJ8zBSSbFwh1H9rgsqvLfV1EoX9sVB8T1ffn52VtksyZUeE7BbqiBjXGJINBh7dddEmowx9Y6iqhutyhP3SAeAMx31rOuK-KGnAxYZSLtw2vPQiwRFZaxDraThWYtbeJarGcIibMpbAdMiyMBA3M4iGKEstn09BWvBrwZ2xbVU5ZNYb7YGbXUnqN3VDi_yjSOl7C8KopC4y5GSyBJgcFACbPjZ7R_oflj0OS3UAfHClobohyKXQ8TmQZ8C83b4SbTPeZ3CjXJodqn2ln_f_5MQeoaIwTBexnjcoj3PrnmzYvtbzTMeXL6je1O1DjJuzwwK2P5pSR7-bToV8r9S51fLS9GutdcHr3-PC6rJOIZPNfO1g_zbUjcL37dLOH68gKuL38uf5RHo2ahGXMU-iOoJCTq73IUY92j5QZVa1yk_i82oS0vSQMAAA==

Logs

Step 0: first-time read of derived value
computing...
derived value: true

Step 1: update root value, should re-compute derived value
computing...
derived value: true

Step 2: read derived value again, should not re-compute derived value
computing...
derived value: true

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

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions