# Do you have any good optimization suggestions for memory usage

**URL:** <https://erlangforums.com/t/do-you-have-any-good-optimization-suggestions-for-memory-usage/3651>\
**Category:** Questions / Help\
**Tags:** erlang, erlang-otp\
**Created:** [May 27, 2024, 1:44pm UTC](https://erlangforums.com/t/do-you-have-any-good-optimization-suggestions-for-memory-usage/3651 "2024-05-27T13:44:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![emmm](https://erlangforums.com/user_avatar/erlangforums.com/emmm/32/2051_2.png) [@emmm](https://erlangforums.com/u/emmm)\
**Post date:** [May 27, 2024, 1:44pm UTC](https://erlangforums.com/t/do-you-have-any-good-optimization-suggestions-for-memory-usage/3651/1 "2024-05-27T13:44:07Z")

</div>

hi,This is the memory usage rate calculated by my system using recon.alloc, which is really too low.  
Do you have a good optimization plan.

Memory used by erlang processes: 873621304 Bytes (833 MB)  
Memory allocated by erlang processes: 875520192 Bytes (835 MB)  
Memory allocated by ETS: 663091648 Bytes (632 MB)  
Memory total allocated: 2368366272 Bytes (2259 MB)  
Memory by erlang vm: 5013745664 Bytes (4781 MB)  
Memory pool usage: 0.454267819836503

machine environment :centos7,opt25

---

<div class="post-metadata">

**Author:** ![TD5](https://erlangforums.com/user_avatar/erlangforums.com/td5/32/1590_2.png) [@TD5](https://erlangforums.com/u/TD5)\
**Post date:** [May 28, 2024, 9:54am UTC](https://erlangforums.com/t/do-you-have-any-good-optimization-suggestions-for-memory-usage/3651/2 "2024-05-28T09:54:39Z")

</div>

It really depends on what the structure of the data actually is, but common ones that come to mind for me:

- Replace list-strings with utf8-binaries, since they are typically much more compact since they don’t need a reference for every character to point to the next node of the list.
- Swap lists for tuples for similar reasons to the above, where applicable. If you have fixed-sized lists, consider whether tuples may be a better fit.
- Replace constant strings with atoms (e.g. if you are tagging data with strings rather than atoms), since you essentially get simple and cheap interning (sharing) by using atoms instead.
- Reduce the creation of garbage or duplicated data by sharing as much of values as possible.
- Investigating compressing your ETS tables, by using the `compressed` option on the table itself, or directly using a compression function on the data.

---

<div class="post-metadata">

**Author:** ![emmm](https://erlangforums.com/user_avatar/erlangforums.com/emmm/32/2051_2.png) [@emmm](https://erlangforums.com/u/emmm)\
**Post date:** [May 28, 2024, 12:13pm UTC](https://erlangforums.com/t/do-you-have-any-good-optimization-suggestions-for-memory-usage/3651/3 "2024-05-28T12:13:22Z")

</div>

Thank you, your answer has greatly inspired me. I have been searching for this question recently. I’m not sure which part of the problem it is at the moment. Is there any relevant tool available to troubleshoot it?

---

<div class="post-metadata">

**Author:** ![TD5](https://erlangforums.com/user_avatar/erlangforums.com/td5/32/1590_2.png) [@TD5](https://erlangforums.com/u/TD5)\
**Post date:** [May 28, 2024, 1:42pm UTC](https://erlangforums.com/t/do-you-have-any-good-optimization-suggestions-for-memory-usage/3651/4 "2024-05-28T13:42:46Z")

</div>

Not too sure about memory profilers - that’s probably something that can just be searched for online - but the [erts\_debug](https://github.com/erlang/otp/blob/master/lib/kernel/src/erts_debug.erl) module is handy for comparing the sizes of terms. See the `size` and `flat_size` functions.
