[Low] Memory Fragmentation in Message Buffer Reuse #24

Open
opened 2026-02-11 19:31:46 +00:00 by thabeta · 0 comments
Owner

Issue

The message subsystem's buffer management strategy for peer-to-peer communication leads to heap fragmentation in long-running mycelium nodes.

Location

mycelium/src/message/

Problem Description

Messages are frequent and varied in size. The current approach of allocating and deallocating Vec for every message causes high churn in the global allocator and subsequent memory fragmentation, especially on memory-constrained devices (routers/mobile).

Impact

  • Severity: LOW (Optimization)
  • Frequency: Long-running production nodes
  • User Impact: Increased memory usage over time, slower performance

Remediation

  1. Implement a pool of pre-allocated buffers (Buffer Pool)
  2. Use a crate like bytes or pooled to manage shared memory slices
  3. Standardize message transmission sizes where possible to reduce allocation classes

Testing

  • Run node with jemalloc-stats under continuous high traffic
  • Monitor fragmentation and memory growth over 24+ hours
## Issue The message subsystem's buffer management strategy for peer-to-peer communication leads to heap fragmentation in long-running mycelium nodes. ## Location `mycelium/src/message/` ## Problem Description Messages are frequent and varied in size. The current approach of allocating and deallocating Vec<u8> for every message causes high churn in the global allocator and subsequent memory fragmentation, especially on memory-constrained devices (routers/mobile). ## Impact - **Severity**: LOW (Optimization) - **Frequency**: Long-running production nodes - **User Impact**: Increased memory usage over time, slower performance ## Remediation 1. Implement a pool of pre-allocated buffers (Buffer Pool) 2. Use a crate like `bytes` or `pooled` to manage shared memory slices 3. Standardize message transmission sizes where possible to reduce allocation classes ## Testing - Run node with `jemalloc-stats` under continuous high traffic - Monitor fragmentation and memory growth over 24+ hours
Sign in to join this conversation.
No labels
Urgent
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
geomind_code/mycelium_network#24
No description provided.