cronos icon indicating copy to clipboard operation
cronos copied to clipboard

Problem: memiavl has relatively big gc pressure

Open yihuang opened this issue 2 years ago • 0 comments

Depending on the traffic of the chain and interval of snapshot rewriting, memiavl need to manage lots of small memories for MemNodes and key/value slices, which could put a big pressure to golang GC, it might make sense to use some manual memory management.

Memory Arenas

One obvious solution is memory arenas feature introduced in go 1.20, we just allocate these objects with big chunks of arenas.

Negatives

  • we can't reclaim and reuse memory, arenas don't support deallocating, before dropped as a whole when we switch snapshot, it's maybe alright assuming deletion happens more rarely than insertion/updates.

Manual Memory Management

  • Implement MemNode as a []byte, similar to the nodes in mmap-ed snapshots, allocate in a big buffer, maintain an intrusive free list to reuse nodes.
  • Leave key/value slices to golang GC.

yihuang avatar Apr 20 '23 08:04 yihuang