STINNER Victor added the comment:

> So, apparently, it's not the nodes themselves taking up a disproportionate 
> amount of memory -- it's the heap getting so badly fragmented that 89% of its 
> memory allocation is wasted.

Yeah, the Python parser+compiler badly uses the memory allocator. See my 
"benchmark" for the memory allocator: python_memleak.py.

The classical pattern of memory fragmentation is:

* allocate a lot of small objects
* allocate a few objects
* allocate more small objects
* free *all* small objects

All objects must allocated on the heap, not mmap(). So the maximum size of a 
single object must be 128 KB (usual threshold used in malloc() to switch 
beetween the heap memory and mmap).

We can try various hacks to reduce the fragmentation, but IMHO the only real 
fix is to use a different memory allocator for the compiler and then free 
everything allocated by the parser+compiler at once.

We already have an "arena" memory allocator: Include/pyarena.h, 
Python/pyarena.c. It is already used by the parser+compiler, but it's only used 
for AST objects in practice. The parser uses the PyMem allocator API (ex: 
PyMem_Malloc).

----------
nosy: +haypo
Added file: http://bugs.python.org/file42091/python_memleak.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue26415>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to