Skip to content

Dev performance reduced by add_owner_to_object calls when using a $state.raw and a context created by a function #15072

Closed
@thes01

Description

@thes01

Describe the bug

This issue happens in the development mode only. I believe this bug is somewhat related to #14491, respectively to the fix #14533, which helps with this case for classes, but not functions.

Steps to reproduce:

  • set a context that is a POJO with a $state.raw field (e.g. by using a factory function)
  • fill the $state.raw with something sufficiently deep
  • have multiple child components mount and call getContext to retrieve the context (same symptom as in the referenced PR)

Reproduction

https://svelte.dev/playground/ab1f18a235f44df28eae50837df5bc1d?version=5.19.0

The Svelte REPL apparently cannot build the component in a dev mode, therefore you need to run it in localhost. What I see in the devtool performance monitor is something like this:

Image

Looking at the getContext implementation, it is understandable why this happens. The add_owner_to_object simply recurses into the fields of the state. I hope this could be addressed so that people who don't use classes (for whatever reason) aren't surprised by this.

Logs

System Info

System:
    OS: Windows 11 10.0.26100
    CPU: (16) x64 AMD Ryzen 7 PRO 6850U with Radeon Graphics     
    Memory: 3.64 GB / 14.76 GB
  Binaries:
    Node: 22.9.0 - ~\AppData\Local\fnm_multishells\23524_1737450727692\node.EXE
    Yarn: 1.22.22 - ~\AppData\Local\fnm_multishells\23524_1737450727692\yarn.CMD
    npm: 10.9.0 - ~\AppData\Local\fnm_multishells\23524_1737450727692\npm.CMD
  Browsers:
    Edge: Chromium (131.0.2903.146)
    Internet Explorer: 11.0.26100.1882

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