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

x2 memory usage + potentially memory leak. #221

Closed
punksta opened this issue Apr 20, 2020 · 11 comments
Closed

x2 memory usage + potentially memory leak. #221

punksta opened this issue Apr 20, 2020 · 11 comments

Comments

@punksta
Copy link

punksta commented Apr 20, 2020

I was debugging out-of-memory errors of production app and found that

  1. Hermes used about twice more RAM memory comparing to JSC.
  2. it didn't free unused memory.

android performance RAM monitor

tested on:

  • react-native 61.5
  • debug build type
  • production, minified, JS
  • android emulator x86, api 29

hermes 0.2.1

image

JSC r241213

image

You can clearly see how memory was growing and wasn't getting free

note

I think it's something either related to json parsing or fetch api because the app loads large json objects (10*5mb)

@avp
Copy link
Contributor

avp commented Apr 20, 2020

This seems related to #164, which discusses a memory leak in WeakMap that was fixed in 0.4.1.

It seems likely that the fix is related to your issue - can you try upgrading Hermes and seeing if that works? Note that Hermes 0.4.1 works with RN 0.62.0.

@punksta
Copy link
Author

punksta commented Apr 20, 2020

@avp yep. But I can try upgrading no earlier than next week. JSC solves my current problem

@sinxwal
Copy link

sinxwal commented Jun 29, 2020

@punksta Have you checked Hermes 0.4.1?
In my case the memory usage is still huge.

@punksta
Copy link
Author

punksta commented Jun 30, 2020

@sinxwal unfortunately I just switched to JSC and I don't have time for experiments. I will update this issue if I try it.

@sinxwal
Copy link

sinxwal commented Jun 30, 2020

@punksta Thanks, mate. Switching to JSC is so expensive(

@punksta
Copy link
Author

punksta commented Jun 30, 2020

@sinxwal you mean things like facebook/react-native#25494 ?
It is painful, but for my current project it isn't as bad as memory leaks. Basically I am just hoping that it will be fixed one day.

@punksta
Copy link
Author

punksta commented Oct 30, 2020

I tested the app again.

  • React-native 63.2
  • production, minified js, release build type, with android studio profiler on
  • android v21 emulator

Hermes

image

JSC

image

Memory leak seams resolved. Memory usage is also much better.

@punksta punksta closed this as completed Oct 30, 2020
@tmikov
Copy link
Contributor

tmikov commented Oct 30, 2020

@punksta do you have an idea why the Java memory and the stack are so different between the two graphs? Shouldn't they be the same?

@punksta
Copy link
Author

punksta commented Oct 31, 2020

@tmikov Indeed stack usage is very different: 20mb (hermes) vs 1.2mb (jsx). But I don't know why, unfortunately

@tmikov
Copy link
Contributor

tmikov commented Oct 31, 2020

@punksta AFAICT, it is the opposite: 1.2mb Hermes vs 20mb jsc. That actually makes sense - Hermes doesn't use the native stack, while JSC does. So the Hermes "stack" would count as "native memory". If we add them together we get about 75MB total native memory, approximately the same between both engines. Which is disappointing for us, of course, but not awful.

There are two remaining mysteries:

  • Why is the Java memory so different?
  • Is your application deeply recursive? 20MB is a lot of stack.

@punksta
Copy link
Author

punksta commented Oct 31, 2020

@tmikov you are right. I can't recall any deep recursions in the app.

Let me describe what the app does. It loads about 80mb by chunks and writes it into sqlite.

So data flow is the following:

okhttp -> react-native-fetch-blob -> javascript engine -> react-native-sqlite-2 -> sqlite

I assume that gc could not release memory allocated for java objects in one of these components.
Stack memory was already taken the loading started. So it's something else.

I will try to explore memory dump.

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

4 participants