byte arrayForHeapAllocation = new byte[100 * 1024 * 1024];
arrayForHeapAllocation = null;
On our production app that loads a lot of libraries at startup, we saved a full 30 seconds on startup by adding this.
I'd like some input on which strategy to use for this. I see at least two ways to go:
I like the second option better, since reading and parsing a file at app startup will add to startup time instead of reducing it.
@ruboto Any thoughts?
@headius @rscottm Any thoughts on the strategy to choose?
* Issue #176 ruboto-176 Add option to allocate large heap at startup
Sorry, not sure I have enough knowledge to judge. Isn't large heap specified in the manifest?
The maximum heap size is a manifest attribute, yes.
What I have discovered is that the actual heap is allocated in minimal size chunks, keeping the allocated heap size as small as possible. What I have tried is forcing the allocation of a larger actual heap at the start of an application, removing the need for further heap allocation. This had no effect on a minimal Ruboto app, but a dramatic effect on a large Ruboto app using multiple gems.
It would be nice to reduce the base amount of memory required at startup.
I can't even start the irb, it crash with an 'out of memory'
kmmndr, what device are you using? Most devices seem to have enough heap to get it running. On the WIMM One watch, I had to go through a few things to reduce the number of files in the apk. I found that a large chunk of heap was taken up tracking all the files. I ended up removing most of the timezone files in Joda, and making a separate archive of all the stdlib files (unpacking them at start up). We might need to do something like this to reach some devices. I also wonder if it might speed up start up speed.
I'm using a Geeksphone Zero (http://www.geeksphone.com)
Phone manufacturers have the freedom to set their own max heap. The original G1 only had 16Mb (not sure if they increased that with subsequent OS roll outs). I don't see anything that says what your devices' heap is, but my guess is that they set it to 16Mb. I definitely saw a problem with that small a heap on the WIMM One. I'm assuming you're running stock. I've seen a few references to the ability to increase the heap size within custom ROMs.
I don't really know how high is max heap on this phone. If it can be changed, maybe cyanogen team has changed the value. I'm running CM7 (one of the latest release candidate)
I'm not running CM7, but I saw one reference to a setting: Settings -> CM Settings -> Performance -> VM Heap Size
Wonderful, it works ! Thank you very much :-)
* Issue #176 Add option to allocate large heap at startup