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

Memory Leak in Group Event Registration (via timeline.setGroups()/timeline.setData()) #183

Closed
aphix opened this issue Nov 13, 2019 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@aphix
Copy link

aphix commented Nov 13, 2019

Fiddle/Example

Use the 'Memory' tab in your browser's developer tools to watch the memory usage over time.
In the below example I see ~65,000 callbacks and ~90mb memory usage after 60 seconds.

image

Here's a complete JS Fiddle demonstrating the leak.

Line 52 is causing the leak in the above example.

Description/Analysis

The leak occurs when calling timeline.setGroups (or timeline.setData) with any number of groups.

The number of items does not appear to affect this, and this issue does not appear to occur simply when setting items, or redrawing, only when using either setGroups or setData to set new groups.

The issue appears to be in Group.js when registering a listener to check for ranged items:

itemSet.body.emitter.on("checkRangedItems", ...fn...) is called on all groups, ignoring whether or not the listener has already been registered on the emitter, leading to a leak of unreleased listeners.

In current revision: Group.js, lines 85-87

This bug was introduced 5 years ago in this commit

Hacky Workaround

Simply delete timeline._callers.checkRangedItems before redrawing or setting new data.

Next Steps

I'm not familiar enough with the library to comfortably submit a PR without knowing the ramifications of the change (or if there are other things that rely on this behavior), however if it will greatly increase the speed of getting this fixed and merged, then perhaps I can spend some time over the next week to create a suitable patch.

Please let me know if you have any other questions, if there is trouble reproducing, or if I need to provide any other details.

Thanks,
Aphix

@yotamberk yotamberk added the bug Something isn't working label Nov 16, 2019
@tmalatinszki
Copy link

Hi,

Are there any plans to have it fixed in one of the upcoming releases? If not, is there any way to apply the mentioned workaround if I am using ngx-vis?

Thanks,
Tamás

@yotamberk yotamberk self-assigned this Dec 28, 2019
yotamberk added a commit that referenced this issue Dec 28, 2019
Thomaash added a commit that referenced this issue Feb 13, 2020
This is my attempt at solving #183.

There are two key differences when compared to #235:
1. This one actually works better.
2. This one doesn't blindly throw away all listeners.

Leaks in my tests (very rough measurements on my device):
- Upstream: 3 MB/s
- #235: 250 KB/s
- This: about 0 KB/s

PS: For the tests I used the JSFiddle MWE from @aphix. I just decreased
delays to leak more memory in shorter amount of time.
yotamberk pushed a commit that referenced this issue Feb 14, 2020
* fix(item-set): don't leak memory when setting groups

This is my attempt at solving #183.

There are two key differences when compared to #235:
1. This one actually works better.
2. This one doesn't blindly throw away all listeners.

Leaks in my tests (very rough measurements on my device):
- Upstream: 3 MB/s
- #235: 250 KB/s
- This: about 0 KB/s

PS: For the tests I used the JSFiddle MWE from @aphix. I just decreased
delays to leak more memory in shorter amount of time.

* style(groups): fix spelling etc. in a comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants