Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to optimise the memory usage?

We developed a custom clock face for Fitbit, but there is an issue with memory usage.

The Fitbit has a max memory of 65kb. With our clockface, we are generally surfing around the 32kb mark. Are there any ways in which we can optimize memory usage? At about 45kb/65kb the app crashes.

Best Answer
0 Votes
4 REPLIES 4

Basic javaScript optimization works. Lots of links exist https://codeutopia.net/blog/2009/04/30/optimizing-javascript-for-extreme-performance-and-low-memory-...

 

I use the following a lot:

Reduce variable name lengths.

Use local variables, avoid globals. 

Functionalize repetitive code.

Initialize from files rather than explicit code. Personally I use the i18n file system to store initial values.

Move process intensive code off the watch to the phone where process time and space is relatively free.

Use an IDE like Visual Studio Code, minifier extensions are very helpful, especially the automated ones like "JS & CSS Minifier (Minify)"

 

I managed to fit quite a lot into my most recent watchface.

 

Watchface is ILuvChrono

https://gallery.fitbit.com/details/bda6f514-3946-49ba-a4ed-75e8470ab034 

ILuvChronoAnim.gif

Best Answer
0 Votes

In general, I don't think you need to use short variable names, because the Fitbit build process includes minification. Take a look inside an .fba (it's just a .zip by another name).

 

An exception is class attribute names.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

There's more Fitbit-specific memory tips here.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Hello Catplace,

 

I do appreciate your comments; however,... my mileage varied.

 

Yes. You're right Fitbit does minify, but I've found the difference between what is done:

 

morningReign_0-1574483320764.png


and what a more aggressive minifier can do:

 

morningReign_2-1574483398421.png

 

Has been the difference between having memory errors and not

 

Also,...

 

Variable length names do not minify for SVG elements or items that pass from module to module

 

Also,...

 

While cbor does reduce the transmission size, the max memory use appears to ultimately be higher as the decoding and encoding are done.

 

Actually,... the biggest offenders I've had for memory errors were timers and peersockets.

 

Always clearinterval before creating anew. Orphaning a setInteval does not seem to put it to bed.

 

Make sure your code never adds the same listener more than once. One of my mistakes had the heart monitor displayon listener stack over and over until the watchface died.

 

And break up your communication telegram objects. Bigger objects use more memory than one would think. This one was particularly hard to track down as the memory error would occur before the telegram was actually received.

 

Regards,

Reign

Best Answer