Skip to content

feat: use a WeakMap instead of a symbol to link proxies to values #12868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

Rich-Harris
Copy link
Member

Since #12867 doesn't really work, I figured we could try a WeakMap approach. It's possible that the performance implications will be a dealbreaker.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

Copy link

changeset-bot bot commented Aug 15, 2024

🦋 Changeset detected

Latest commit: 8f5a2b6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -10,7 +10,7 @@ import { queue_micro_task } from '../../task.js';
*/
function is_bound_this(bound_value, element_or_component) {
// Find the original target if the value is proxied.
var proxy_target = bound_value && bound_value[STATE_SYMBOL]?.t;
var proxy_target = bound_value && proxies.get(bound_value)?.t;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit unrelated: Will this logic even work at all now? If it gets the underlying value, which IIUC is the original object, that one will likely not be the current value because of the change

@trueadm
Copy link
Contributor

trueadm commented Aug 17, 2024

Some benchmarks comparing a large table benchmark running locally on some core operations:

Main:

Screenshot 2024-08-17 at 15 46 37

This PR:

Screenshot 2024-08-17 at 15 45 00

So whilst there is a performance loss, it doesn't seem like it's a huge regression. However, it is still a regression and likely one we need to consider vs alternative approaches. The other approach is to dynamically create the proxy object in a closure and thus have access to the metadata that way – which might be faster than a WeakMap, but I have reservations on that.

@trueadm trueadm closed this Aug 20, 2024
@trueadm trueadm deleted the state-symbol-weakmap branch August 20, 2024 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy