Skip to content

svelte 5.0.0-next.97 performance regression in dev mode #11117

@michealparks

Description

@michealparks

Describe the bug

We've recently begun working on a Svelte 5 compatible next branch in the Threlte repo. Upgrading from next.95 to next.97 causes a large performance regression in dev mode.

While devtools spelunking I found one suspect - and this was a bit of a wild guess: it appears that in dev mode every getContext() call triggers a traversal of all object properties of the context. In Threlte apps getContext can be called quite often, and these contexts contain Three.js objects, which contain many properties, some of which trigger side effects on get calls. For example, it triggers a console.warn on this property:
Screenshot 2024-04-11 at 00 34 30

I'm not sure the exact penalty here, and I couldn't find evidence that traverse_for_owners was eating up a lot of CPU, so this could be an unrelated issue / red herring, although I could tell performance was being affected by this warn logging many times for even a simple example.

Here is a comparison of some quick screenshots of profiling next.95 and then next.97 from scene init to first complete render of the positional audio example in our docs:

Screenshot 2024-04-11 at 00 49 29 Screenshot 2024-04-11 at 00 47 04

I haven't done any profiling but the production version of next.97 doesn't seem to have this issue (a production preview of the docs upgraded to next.97 can be found here and the upgrade PR here if relevant)

Happy to follow up any questions and help!

Reproduction

  • Clone Threlte and go to the next branch.
  • upgrade svelte to next.97 in apps/docs/package.json
  • pnpm i && cd apps/docs && pnpm dev. This will start the docs site locally.
  • Navigate to any extras example and monitor performance.

Logs

No response

System Info

System:
    OS: macOS 14.3.1
    CPU: (8) arm64 Apple M2
    Memory: 134.78 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.0 - /usr/local/bin/node
    npm: 10.2.4 - /usr/local/bin/npm
    pnpm: 8.15.1 - ~/Library/pnpm/pnpm
  Browsers:
    Chrome: 123.0.6312.124
    Safari: 17.3.1

Severity

blocking an upgrade

Metadata

Metadata

Assignees

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