-
Notifications
You must be signed in to change notification settings - Fork 893
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
Huge Memory Leak Issue #4416
Comments
I'm sure the Firestore team will look into this but since the problem is related to |
Sorry to hear about your troubles. As suggested above, could you please post the code where you're using |
@hsubox76 @var-const Here is the code sample: I'm also storing the returned function from documentNameArray.forEach(name => {
unSub.push(db.collection(collection).doc(name).onSnapshot(this.handleFirebaseUpdates));
});
handleFirebaseUpdates = (snap) => {
const snapData = snap.data();
if (!snapData) return;
this.setState({ snapData })
} I earlier thought that may be it is due to the fact that I'm processing the updates in the But I observe the continuous memory increase on each call of the PS: the memory usage increases more and more with number of documents I listen to simultaneously, I expect memory consumption to be a little high around 200-300 Mb but as you see going as high as 929 MB the tab crashes. |
Can I ask where in your code the |
In addition to @hsubox76's question, can you please check whether memory usage still spikes if you comment out |
@hsubox76 Yes I am sure that the loop is only running once and all the listeners are created only once. @var-const Yes I tried removing everything from the function and still got the memory issue. One point that i want to add here is that could issue be due to the fact that all the listeners are receiving some big chunk of data at realtime, let's say 200-300 KB on almost all the listeners almost at the same time ?? |
The size of the docs could contribute to the issue. Can you please clarify:
|
Hi @var-const please follow the details:
|
@var-const a gentle reminder over the issue, do you have anything over this ? |
@Sa-meer Apologies for the slow reply. I will try to reproduce the issue based on the information you provided today and will post back here. Just to clarify -- are all of the listeners document listeners (attached to a |
@var-const all are the document listeners. no query or collection listeners. |
Update: I see memory usage go up to 900+MB in spikes when I use 40 listeners, 300kb documents, and 3 updates per second for each document. I will next check if there are any leaks or any low-hanging fruit to reduce memory usage. |
I'm sorry I'm slow with updates. I'm still working on this issue. So far, I don't see any leaks related to listeners or documents -- all memory allocated appears to be garbage-collected. However, I noticed a potential issue with WebChannel -- I need to do more research before I can say whether it's an actual bug or a red herring. I'll keep posting updates as I have them. |
Thanks, please keep me updated because this issue is directly affecting my application performance when data is more frequent and big. |
Hi @var-const any update on this ? |
I can confirm that with high traffic, the Web Channel memory consumption can increase significantly (up to 300MB on newer versions of Chrome and even higher than that on older ones). This is because new server responses get attached to the same I couldn't identify any leaks related to documents or listeners. The memory gets deallocated as expected (except that the latest version of each document gets cached). 300KB docs * 3 updates per second * 40 listeners would result in roughly 35MB of memory usage per second; this adds up quickly, and I presume garbage collection simply doesn't get triggered fast enough to prevent memory usage from increasing significantly. Perhaps there's a way to restructure your app to reduce the amount of traffic (if you could share some details on your use case)? |
Well the restructuring of the app is always an option but I was looking for a solution with the my current structure, because I'm not doing something very out of the box here just the size and frequency of updates is on a little higher side. So the common concussion here looks like: |
One thing you can try is to enable long polling in the settings. It's primarily intended to work around issues with proxies and antivirus software, but because it prevents buffering of the responses, it might help here in case a significant part of the memory usage you're seeing comes from the WebChannel buffering. Can you please try that out and let us know if it makes any difference? |
Thanks for this suggestion, I'll try |
Hey @var-const so I applied the setting change of Is there anything else possible to overcome this issue that you can suggest ? |
Thank you for reporting your experience -- this does confirm that the memory consumption is significantly affected by the WebChannel issue. Unfortunately, it's an issue in one of our dependencies and not something we can fix. Forcing long polling makes WebChannel establish a new connection for each document update, so it is expected that updates would take longer; it will also increase the traffic. This brings up another point -- while the current levels of traffic cause problems with memory consumption, they are also likely to be undesirable for users. If there was a way to restructure the data model or the app to reduce the traffic, it will be an improvement in the user experience. One thing that comes to mind -- in a given update, how much of the document is typically modified? If documents have a relatively small part that gets updated frequently and a large part that is only updated occasionally or not at all, splitting such documents into two different documents can help reduce the traffic. I don't know if this applies to your use case, though. We are always looking for ways to improve the performance, but unfortunately there's nothing in the short term that is likely to make a difference. |
Closing the issue for now. If we get an update on the WebChannel issue, I'll post it here. |
[REQUIRED] Describe your environment
[REQUIRED] Describe the problem
When I start the onSnapshot() listener on multiple documents the memory utilisation go sky rocket.
So the Browser Tab crashes if there are multiple (10-15) listeners are running simultaneously.
This is how I'm adding my config for firestore:
There is no processing is going on the data recived from the onSnapshot(), only making the connection and I can see heavy memory usage.
On each auto Garbage collection Memory usage drop and as data flows on the listener again it go up and this continues.
The text was updated successfully, but these errors were encountered: