1
Memory allocation pitfalls
Mamy Ratsimbazafy edited this page 2020-08-27 08:35:12 +02:00
There are a couple of common pitfalls that unnecessary allocates memory and may seriously impact performance by:
- introducing GC latency
- increasing memory fragmentation
- introducing unnecessary indirection
- introducing unnecesary instruction
- preventing compiler optimizations
Example: https://github.com/status-im/nim-beacon-chain/pull/1573
Those common ways are:
[]
slicing instead of toOpenArray- Iterating with implicit
items
on an array/array fields. This is solved in Nim devel (https://github.com/nim-lang/Nim/issues/14421), but not in the 1.2.x branch that we target.