Skip to content

Add option to allocate large heap at startup #176

Closed
donv opened this Issue May 9, 2012 · 13 comments

3 participants

@donv
Ruboto member
donv commented May 9, 2012
        byte[] arrayForHeapAllocation = new byte[100 * 1024 * 1024];
        arrayForHeapAllocation = null;
@donv
Ruboto member
donv commented May 25, 2012

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:

  • Include a config file in the apk that is read at startup and allows for different startup preferences.
  • Use the Ruboto.yml config to modify source during build to set the startup preferences.

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?

@donv
Ruboto member
donv commented May 26, 2012

@headius @rscottm Any thoughts on the strategy to choose?

@rscottm
Ruboto member
rscottm commented Jun 6, 2012

Sorry, not sure I have enough knowledge to judge. Isn't large heap specified in the manifest?

@donv
Ruboto member
donv commented Jun 7, 2012

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.

@rscottm
Ruboto member
@donv
Ruboto member
donv commented Jun 9, 2012
@kmmndr
kmmndr commented Jun 12, 2012

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'

@rscottm
Ruboto member
rscottm commented Jun 14, 2012

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.

@kmmndr
kmmndr commented Jun 14, 2012

I'm using a Geeksphone Zero (http://www.geeksphone.com)

@rscottm
Ruboto member
rscottm commented Jun 14, 2012

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.

@kmmndr
kmmndr commented Jun 14, 2012

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)

@rscottm
Ruboto member
rscottm commented Jun 14, 2012

I'm not running CM7, but I saw one reference to a setting: Settings -> CM Settings -> Performance -> VM Heap Size

@kmmndr
kmmndr commented Jun 15, 2012

Wonderful, it works ! Thank you very much :-)

@donv donv was assigned Jun 6, 2013
@donv donv closed this Jun 6, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.