06-07-2018 12:42
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

06-07-2018 12:42
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
Composed my answers on different topics to the document with guidelines. If you ever encountered out of memory exception, it worth reading. Enjoy.
https://github.com/gaperton/ionic-views/blob/master/docs/optimization-guidelines.md
06-07-2018 16:12
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

06-07-2018 16:12
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
That's amazing! Thank you so much for providing this!

06-08-2018 02:11
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

06-08-2018 02:11
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
Excellent article!
I have a couple of questions regarding the last part 'Use functions instead of hashmaps and arrays to save heap memory'. Although you are saving memory by using the function, doesn't the function itself take up memory? Just wondering if the function itself would be larger than 64 bytes?
This leads me to my second question. Does code sit in the same 64K as the heap? If not, where does the code sit and how large can it be?
06-08-2018 08:42 - edited 06-08-2018 10:46
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

06-08-2018 08:42 - edited 06-08-2018 10:46
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
> Does code sit in the same 64K as the heap?
That's the good question. There's nothing said about that in the docs, and I assumed that the heap is separate. But let's check.
14010 - is the maximum x length while the simulator doesn't throw out of memory exception for this code.
const x = new Float32Array( 14010 ); const y = { a0 : "sasasasa", a1 : "sasasasa", a2 : "sasasasa", a3 : "sasasasa", a4 : "sasasasa", a5 : "sasasasa", length : "sasasasa" } console.log( x.length, y.length );
When we change the code like this - it throws "out of memory".
const x = new Float32Array( 14010 ); function y( k ){ switch( k ){ case 'a0' : return "sasasasa"; case 'a1' : return "sasasasa"; case 'a2' : return "sasasasa"; case 'a3' : return "sasasasa"; case 'a4' : return "sasasasa"; case 'a5' : return "sasasasa"; case 'length' : return "sasasasa"; } } console.log( x.length, y.length );
Apparently, it's not that simple, and this "optimization" make things worse. It's either the code is located in the heap or the heap with a code segment share the same memory quote. And that was the single thing I didn't really check myself 🙂
Will change an article accordingly, thanks.
06-08-2018 08:59
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

06-08-2018 08:59
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
Updated the article. Now it's documented as an antipattern, which you need to avoid 🙂 Surprise. @Mark-D, thanks a lot!
https://github.com/gaperton/ionic-views/blob/master/docs/optimization-guidelines.md#do-not-use-funct...
06-08-2018 13:23
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

06-08-2018 13:23
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
Yes, now I'm pretty sure that both the code and the heap lives under the same quote, which is slightly less than 64KB.
https://dev.fitbit.com/build/reference/device-api/system/
import { memory } from "system"; console.log("JS memory: " + memory.js.used + "/" + memory.js.total);
