Optimizing Variables and Arrays for Memory

Discuss Lemur and share techniques.
Post Reply
rad3d
Newbie
Posts:32
Joined:27 Nov 2015 04:15
Optimizing Variables and Arrays for Memory

Post by rad3d » 09 Jan 2016 16:12

I have a template that uses presets to store fairly large sets of variables and arrays. Many of these variables are either on/off states or only need to store small integers (many don't go above 3-4). Obviously, the more presets I store, the more it eats into my template's memory usage.

I'd like to optimize the way I store presets to get everything as efficient as possible. Just wondering if anyone else has used any specific techniques for this before I start down more of a bit-level trail.

rad3d
Newbie
Posts:32
Joined:27 Nov 2015 04:15

Re: Optimizing Variables and Arrays for Memory

Post by rad3d » 10 Jan 2016 12:59

I did a few quick tests, and it 'appears' that 1 long array is potentially more memory efficient than several smaller ones - assuming I stay inside of the guidelines for array sizes stated in the manual.

For example, the array expression below appears to take up the same 8192 bytes as a single expression variable that equals 0:
{127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127, 127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127}

Is my assessment correct here, and would I be correct in assuming my template will be more memory efficient if I group many of my single expressions - or even shorter arrays - together into longer arrays? Again, this is more for how I handle large sets of data for presets, for which I have functions for creating and parsing these arrays.

And how does my project memory affect Lemur's overall usage in iOS - especially when it comes to running it along side other iOS apps? Just want to make sure that making these changes will be worth the effort.

rad3d
Newbie
Posts:32
Joined:27 Nov 2015 04:15

Re: Optimizing Variables and Arrays for Memory

Post by rad3d » 11 Jan 2016 22:45

Guess it's just me out here... :D

Went ahead and made my updates. Major difference in Lemur's memory readings.

Before the 5.3 upgrade, my template was up around 88% and I was doing everything I could to optimize, but was only able to shave a few percentage points off here and there. When 5.3 came out, my template magically went down to 47%.

After making my preset array changes - essentially translating 48 presets, each containing a little over 100 expressions (mixture of ~8 element arrays and a handful of singles), to about 20 expressions in each, combining the exact same data into much larger arrays - my template has now dropped to 23% - and I've actually added quite a bit extra to it since it was 88%.

So far, no issues with the data. Still not sure if this translates to less memory usage when the template is active, though assuming that's the case.

Thought this might be of interest to anyone else storing large sets of data in their templates.

Post Reply