Python and Ruby memory profilers miss C heap allocations, undercounting native memory use
A developer found that Python's tracemalloc reported about 9.5 KB per compiled query rule, while macOS malloc statistics showed roughly 142 KB per instance. Ruby's ObjectSpace similarly hid over 137 KB of native heap behind a single wrapper slot when wrapping the same C library. The gap arises because libc malloc and calloc calls made by C extensions bypass Python's allocator hooks and Ruby's GC accounting, unless the extension reports its memory (for example by setting .dsize in Ruby). The author recommends pairing VM profilers with OS allocator statistics and process RSS, and provides small Python and C probes that read macOS malloc zone statistics and peak resident memory.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in