hippware / rn-chat

MIT License
5 stars 0 forks source link

Investigate app memory usage #4055

Open bengtan opened 5 years ago

bengtan commented 5 years ago

There was one instance around Feb 3rd 2020 where low_memory warnings were correlated with the app crashing. See https://hippware.slack.com/archives/C2V6L53TQ/p1580781852115000?thread_ts=1580745379.101800&cid=C2V6L53TQ

We should investigate memory usage and/or try to improve it (if not too much work). For example:


(Original Post)

Bit worried about the app being killed by the OS if it uses too much memory.

This has been mentioned (by me) as a possible cause of #4037.

bengtan commented 4 years ago

There was one instance around Feb 3rd 2020 where low_memory warnings were correlated with the app crashing. See https://hippware.slack.com/archives/C2V6L53TQ/p1580781852115000?thread_ts=1580745379.101800&cid=C2V6L53TQ

We should investigate memory usage and/or try to improve it (if not too much work). For example:

aksonov commented 4 years ago

App uses about 220Mb. But... Occasionally found memory leak today, by pressing menu button, so now it uses 254 after many many menu button taps. I will investigate more

bengtan commented 4 years ago

FYI, when I (very briefly) looked at this last year, I looked for a component which could retrieve the amount of memory being used by the app and found react-native-vitals.

https://github.com/robinpowered/react-native-vitals

YMMV.

aksonov commented 4 years ago

Very useful article: https://blog.swmansion.com/hunting-js-memory-leaks-in-react-native-apps-bd73807d0fde

aksonov commented 4 years ago

I did many measurements of app memory usage, but they are very very unstable and not reproducible. Sometimes the difference is bigger, sometimes - smaller, it probably depends from garbage collector.

However I found some evidence where most leaks are placed - from difference snapshot I see many objects are from React Navigation. I was not able to find own app memory leaks - after I reduced code I still saw memory leaks...

Screenshot 2020-03-02 at 18.18.44.png

Similar issue: https://github.com/react-navigation/react-navigation/issues/7078 And some leaks could be from React itself: https://github.com/facebook/react/issues/14732

Even if I don't use react navigation, just tap to see fullscreen map and then tap again to return to previous state I see very small but memory leaks: Screenshot 2020-03-02 at 18.46.14.png

I see similar issue here: and here https://github.com/facebook/react/issues/16138

Measurement results:

======= reduced, without navStore

before:
237mb

After 10 menu open/close attempts

246mb

2. Before:
250mb

254 after

3. 246/249

===== reduced, with navStore
1. before:
246mb

After 10 menu open/close attempts
261mb

2. Before:
229.5

After:
242mb

3. Before:
272

After:
282

4. Before
256Mb

After:
261Mb

==== latest master
Before
249Mb

After 
260Mb
bengtan commented 4 years ago

Some bugsnags with memory stats have been posted (after 4891 was merged).

It's reporting memory usages of 126MB, 89MB, 35MB, 41MB when the low memory warning was triggered. These numbers seem ... okay?

https://app.bugsnag.com/hippware/tinyrobot-1/errors/5e6be5dcb90f3d00176c4caf