Skip to content
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

Keeping elements around for attribution can leak memory #580

Open
noamr opened this issue Dec 15, 2024 · 5 comments
Open

Keeping elements around for attribution can leak memory #580

noamr opened this issue Dec 15, 2024 · 5 comments

Comments

@noamr
Copy link

noamr commented Dec 15, 2024

When we save elements in the node map, they are retained in memory, even after they are removed from the DOM. A DOM element can hold a lot of memory, and also it gets confusing since those retained elements appear in DevTools memory panel.

Perhaps we can retain them as a WeakRef, and save the attribution data instead of the node itself when it's removed?

https://issues.chromium.org/issues/376777343 is an example that I believe originates from webvitals inside devtools retaining nodes.

/cc @brendankenny @tunetheweb

@tunetheweb
Copy link
Member

CC: @adamraine

So at the moment we keep a map of the interactionId to Node, and then use that to get the Selector. We also only keep the last 10 entries (to cover the p98 cases) so it's not a "leak" as such (in that it shouldn't grow and grow).

However, it might be better to save the map of interactionId's to selector anyway as more likely to get a more useful selector if that is done when the element is still in the DOM. The downside to that would be people would be unable to get other attributes from the node (for example, if they didn't like our selector algorithm).

We should also update #562 to stop make this problem worse.

@noamr
Copy link
Author

noamr commented Dec 16, 2024

CC: @adamraine

So at the moment we keep a map of the interactionId to Node, and then use that to get the Selector. We also only keep the last 10 entries (to cover the p98 cases) so it's not a "leak" as such (in that it shouldn't grow and grow).

Right, but it looks like a leak and is nontheless a memory waste.

However, it might be better to save the map of interactionId's to selector anyway as more likely to get a more useful selector if that is done when the element is still in the DOM. The downside to that would be people would be unable to get other attributes from the node (for example, if they didn't like our selector algorithm).

You can probably keep a WeakRef to the node, which would return it if it wasn't removed.

@tunetheweb
Copy link
Member

You can probably keep a WeakRef to the node, which would return it if it wasn't removed.

We only need the Map for cases when it is removed. Otherwise we can get it directly from the event timing entry.

@adamraine
Copy link
Member

issues.chromium.org/issues/376777343 is an example that I believe originates from webvitals inside devtools retaining nodes.

Side note, I think whatever is happening in web-vitals.js is only a part of the problem for this issue. DevTools is doing some extra node retention that may make the problem worse.

@adamraine
Copy link
Member

Is this closable now that #585 has landed?

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

No branches or pull requests

3 participants