11-19-2019 23:26
11-19-2019 23:26
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.
11-20-2019 21:57
11-20-2019 21:57
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
11-21-2019 12:06
11-21-2019 12:06
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.
11-21-2019 12:08
11-21-2019 12:08
There's more Fitbit-specific memory tips here.
11-22-2019 20:45
11-22-2019 20:45
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:
and what a more aggressive minifier can do:
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