element-hq / element-android

A Matrix collaboration client for Android.
https://element.io/
GNU Affero General Public License v3.0
3.38k stars 723 forks source link

Element temporarily consumes >1 GB of "user data" #2620

Open janschejbal opened 3 years ago

janschejbal commented 3 years ago

I apologize, this isn't going to be a great bug report :(

Element Android 1.0.13 consumed >1 GB of "User data" storage on my phone. This grew by hundreds of MB in the matter of minutes. I don't know the cause. I force-stopped the app and denied it background data access (to prevent push notifications from restarting it) to stop the growth (this worked).

I am in a rC3-related chat room (a virtual hacker con that happened about a week ago). I did not see visible activity there, but if someone is spamming/trolling, it's probably in there.

I grabbed an adb bugreport ~30 minutes after I disabled the app. Grepping for "im.vector.app" yields only ~1800 lines and when scrolling through the logcat section, I didn't see anything interesting there either.

After I accidentally tapped on the app, the storage went down to ~90 MB.

The app's WiFi data usage was ~500 MB over the past month, which isn't too surprising given that I also used it for some phone calls. I have a screenshot of the data usage graph that I could use to determine whether significant additional usage happened around the time of the bug (killed the app ~08:30 UTC+1 today).

Developer mode is enabled. Verbose logging is disabled.

Sterrs commented 3 years ago

I had a similar problem a couple of days ago, where element consumed more than 3Gb of user data inexplicably. I uninstalled and reinstalled and it's back down to a reasonable amount. ~This seemed to coincide with me leaving some large rooms, other than that I can't say I have any more information about why this might have occurred.~

Edit: This has since happened to at least one other person I was talking with, without them having left any rooms at all. The user data usage grows enormously quickly.

T-bond commented 3 years ago

I just had the same problem.

Developer mode is enabled. Verbose logging is off. My installation is almost 1 month old. I am using my own Homeserver. I am only in a few Direct chat room, with not much activity. I am also in the Android Element room. And I was in one big room before, but got kicked (for inactivity). I am not sure if I was in that room in this month or before that (so before the app install)

Application version: 1.1.0 F-Droid Android: 11

Application only used 250MB of mobile data and wifi. The current application data is 5.83GB. 15 minutes before it was "just" 3.6GB. It is only data. Cache is around 50MB and does nit change. But the data is drastically increases every minute.

I also just sent in a regshake. I hope some of this information helps.

Edit: After it reached 7GB i force stopped the app. (I did not delete any of the cache or the data) After that I started the app. I think during the splash screen it deleted all the data it just created, as it took a long time. After that I checked the settings again, and it is at 200MB. I will wait and see if it happens again.

Settings

Edit 2: After 1 day of minimal to no use it is already on 1GB. Something is very broken. I will now try to delete data and reinstall.

Edit 3: It is still happens in 1.1.6 Screenshot_20210501-010529_Settings After I checked in the settings, it again reset itself back to 400MB.

shumvgolove commented 3 years ago

Element 1.1.6 from F-Droid, Android 11 This is also happening to me. Element is absorbing around 2gb of storage. After manually force stopping and then opening Element, storage goes back to normal (~235mb).

shumvgolove commented 3 years ago

Still happening with Element 1.2.0 from F-Droid.

T-bond commented 2 years ago

Issue still persist in F-droid variant 1.3.14. Android 12.

I haven't noticed the issue in a while, and one thing changed: I again joined multiple big rooms (with thousands of participants) Before that, I was only in a max 5 member per room. Now Element crashes from time to time, and when I check it uses around 7-8GBof data. After it jumps back to a few hundred of MBs.

Developer mode is not enabled any more, so the problem is maybe not with that.

Memory useage is alo huge. SmartSelect_20220121-141229_Settings

foopub commented 2 years ago

Just to point out, same issue has been reported by multiple other people in the matrix chat room. The experience is very consistent with what is described here already.

A few more details - in my case, the keyboard starts to hide and show sporadically. I do continue to receive messages and am still able to navigate menus with some effort. When I open app info it takes a while for it to load, during which time Element closes (I guess it gets force closed), and user data is high (>5Gb, seen up to 11Gb). After a bit the storage goes back to normal, and upon opening again, Element works normally.

konomikitten commented 2 years ago

Adding my screenshot to this also submitted a Report Bug with the title "GitHub Issue #2620" though anyone looking at that Report Bug should also be aware of what's happening in #5018 for context on the current state Element is in for me.

Screenshot_2022-01-22_06-23-37

element storage usage-2022-01-22-062116
konomikitten commented 2 years ago

Slowly consuming memory and storage: Screenshot_2022-01-22_07-48-09

element-2022-01-22-074846
konomikitten commented 2 years ago

I ended up force stopping the app at 1.3 GB of memory usage and it settled on 2.02 GB of User Data.

konomikitten commented 2 years ago

Still a bug on Element Android 1.3.17.

konomikitten commented 2 years ago

This really needs to be addressed, I'm tired of coming back to Element consuming every single resource available on my phone.

Memory used by apps Storage used by element
opusforlife2 commented 2 years ago

I was just bitten by this bug. Element 1.3.18 (F-Droid) suddenly consumed 1.1 GB of RAM and 1.1 GB of User data. After a short while of doing nothing (I was about to force stop the app, but didn't get to it in time), it is now down to ~50 MB of RAM and ~30 MB of User data.

Can we try a debug version of the app where it starts logging extensively if the RAM used goes above a certain threshold considered "too much", like 500 MB?

foopub commented 2 years ago

Note that this behavior causes other apps to crash too, as Element is hogging resources. It's practically unusable alongside apps that typically run in the background like spotify which keep getting crashed by element.

Would be nice to at least get a response from one of the maintainers.

T-bond commented 2 years ago

Note: I have been using Schildichat for a few weeks now, in order to avoid this issue, and it seems like that it works (the issue is not present in Schildichat).

So maybe checking the differences could help?

ouchadam commented 2 years ago

This has also been coming up in the #element-android room, the tl;dr is the user data storage is not equivalent to network data consumed and the storage is expected to grow during use, killing the app and relaunching will trigger a compaction.

We're using a database called Realm which has a compact on launch feature, the difference in size people are seeing is the database expanding during use and then compacting each time a cold app launch happens (launching after killing the app/rebooting the device)

from the realm docs

The size of a Realm Database file is always larger than the total size of the objects stored within it. This architecture enables some of realm's great performance, concurrency, and safety benefits.


With that said, there may be optimisations we can do to reduce the amount of total entities, features such as read receipts create a lot of entities when in large rooms, I've personally seen a database grow to 2gb and then compact down to 20mb by simply participating in #matrix-hq

as for the RAM usage we would need to investigate further, the matrix protocol is a bit heavier than other messaging apps/protocols as there's a fair amount of client side processing required (especially when it comes to E2EE) which is further exaggerated when participating in many rooms with many users. The issue could be the combination of open connections to the growing database, constant flowing data from /sync due to large amounts of room events (read receipts, messages, E2EE key rotations) or simply memory leaks.

on the RAM topic, it's worth highlighting that ideally your devices and applications want to use as much RAM as possible, unused RAM is wasted RAM :smile: of course there's limits to this when there's memory contention...

I hope this helps clear things up!

tjaderxyz commented 2 years ago

on the RAM topic, it's worth highlighting that ideally your devices and applications want to use as much RAM as possible, unused RAM is wasted RAM 😄 of course there's limits to this when there's memory contention...

This does not explain why there was a very noticeable increase in resource usage at some point in the last month. Before that I never once cared or noticed any slowdown due to that, now around one hour after you use Element it starts to become very slow and eventually uses so much memory that every other app on the phone gets killed. I've seen it get to the point where I couldn't even type in Element, because the keyboard would instantly get killed when I pressed a key.

I don't know if this high resource usage is related to the high storage usage mentioned in this bug's title or if it's a separate issue, but it's very clear to me there's something wrong with Element starting last month.

ouchadam commented 2 years ago

A separate issue would be preferred! The more information we can gather to be able to reproduce locally, the better the chance of us being able to address the issue, such as narrowing down affected versions.

This does not explain why there was a very noticeable increase in resource usage at some point in the last month

this is why I suggested further investigations, RAM usage depends heavily on many moving parts such as OS versions their customisations (garbage collectors/runtimes/memory limits), account usage (amounts of rooms), room activity (member list size, amount of messages, encrypted device keys, encountering spam attacks) etcetc

there's a trade off between thrashing the disk IO and using in memory caches, it sounds like we haven't quite found the right balance~

tjaderxyz commented 2 years ago

A separate issue would be preferred! The more information we can gather to be able to reproduce locally, the better the chance of us being able to address the issue, such as narrowing down affected versions.

I'm not convinced the high data usage and high memory usage are not correlated, but maybe it's best to split the issue.

this is why I suggested further investigations, RAM usage depends heavily on many moving parts such as OS versions their customisations (garbage collectors/runtimes/memory limits), account usage (amounts of rooms), room activity (member list size, amount of messages, encrypted device keys, encountering spam attacks) etcetc

I can tell you I didn't change anything of note in my phone or my Matrix usage around the time Element started to misbehave, and given that there are several other similar reports around the same time I heavily suspect something change in Element.

there's a trade off between thrashing the disk IO and using in memory caches, it sounds like we haven't quite found the right balance~

For me the balance was clearly much better before last month. Now it's borderline unusable.

opusforlife2 commented 2 years ago

killing the app and relaunching will trigger a compaction

I've seen this happen. Apps were slowing down (and Firefox tabs were reloading even more frequently than normal), so I went to Developer options > Running services to see how much RAM Element was taking up. Just before I tapped on the Running services menu, my music app got killed. When the Running services menu opened, Element showed up as "Restarting". Then it changed to a harmless-looking 30 MB, like a wolf in sheep's clothing.

Danacus commented 2 years ago

I have to kill element every day, because it uses 1.5GB of RAM filling all RAM on the device. This slows everything down to the point where the phone is no longer usable and I have to force stop element. This is a big issue for me personally.

wenyifancc commented 2 years ago

Note: I have been using Schildichat for a few weeks now, in order to avoid this issue, and it seems like that it works (the issue is not present in Schildichat).

So maybe checking the differences could help?

The latest Schildichat is based on Element 1.3.12 ,so I tryed element 1.3.12 and it works fine.But I found this bug on Element 1.3.13.

tjaderxyz commented 2 years ago

I'm in 1.4.2 and this bug is still happening, making my phone close to unusable. I have to force kill Element multiple times per day, and often it needs to do an initial sync after being killed. Is there anything we can do to help find the cause of this problem?

Meanwhile I'll be downgrading to 1.3.12 so I can actually use my phone.

konomikitten commented 2 years ago

Meanwhile I'll be downgrading to 1.3.12 so I can actually use my phone.

I tried multiple versions of Element this bug always happens for me I just ended up switching to FluffyChat, it's a lot slower than Element but it doesn't make my phone slow down on a regular basis or need killing frequently. My great hope is that another client Syphon will mature it's the fastest client I've used but lacks Verification and Notifications.

hafiz013 commented 2 years ago

Guys for those who want to why this elemens keep growing the data user storage because matrix itself keep old session without deleting event though u already in new session. Hai deleveloper matrix please enchanced your code to improve memory storage without storage so many session. Below here is the proof why the apps data is increase when refersh token / synch background. Please improve the code

session matrix

foopub commented 2 years ago

This seems to have been resolved for me, not sure which release did it tho. Currently on 1.4.4 (fdroid).

Danacus commented 2 years ago

It is fixed for me too.

opusforlife2 commented 2 years ago

I can't know for certain, but I might have faced it on 1.4.4 as well: https://github.com/vector-im/element-android/issues/5244#issuecomment-1086702812