You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use "Low-fragmentation Heap" memory allocator on Windows #70439
Python has a memory allocator optimized for allocations <= 512 bytes: PyObject_Malloc(). It was discussed to replace it by the native "Low-fragmentation Heap" memory allocator on Windows.
I'm not aware of anyone who tried that. I would nice to try, especially to run benchmarks.
See also the issue bpo-26249: "Change PyMem_Malloc to use PyObject_Malloc allocator?".
We tried it at one point, but it made very little difference because we don't use the Windows heap for most allocations. IIRC, replacing Python's optimised allocator with the LFH was a slight performance regression, but I'm not sure the benchmarks were reliable enough back then to be trusted. I'm also not sure what optimisations have been performed in Windows 8/10.
Since the LFH is the default though, it really should just be a case of replacing Py_Malloc with a simple HeapAlloc shim and testing it. The APIs are nearly the same (the result of GetProcessHeap() will be stable for the lifetime of the process, and there's little value in creating specific heaps unless you intend to destroy it rather than free each allocation individually).
Activity
vstinner commentedon Jan 31, 2016
Python has a memory allocator optimized for allocations <= 512 bytes: PyObject_Malloc(). It was discussed to replace it by the native "Low-fragmentation Heap" memory allocator on Windows.
I'm not aware of anyone who tried that. I would nice to try, especially to run benchmarks.
See also the issue bpo-26249: "Change PyMem_Malloc to use PyObject_Malloc allocator?".
vstinner commentedon Jan 31, 2016
"Low-fragmentation Heap":
https://msdn.microsoft.com/en-us/library/windows/desktop/aa366750%28v=vs.85%29.aspx
vstinner commentedon Jan 31, 2016
The issue bpo-19246 "high fragmentation of the memory heap on Windows" was rejected but discussed the Windows Low Fragmented Heap.
vstinner commentedon Jun 28, 2017
Is there anyway interested to experiment to write such change and run benchmarks with it?
zooba commentedon Jun 28, 2017
We tried it at one point, but it made very little difference because we don't use the Windows heap for most allocations. IIRC, replacing Python's optimised allocator with the LFH was a slight performance regression, but I'm not sure the benchmarks were reliable enough back then to be trusted. I'm also not sure what optimisations have been performed in Windows 8/10.
Since the LFH is the default though, it really should just be a case of replacing Py_Malloc with a simple HeapAlloc shim and testing it. The APIs are nearly the same (the result of GetProcessHeap() will be stable for the lifetime of the process, and there's little value in creating specific heaps unless you intend to destroy it rather than free each allocation individually).
vstinner commentedon Jul 3, 2017
Steve: "We tried it at one point, but it made very little difference (...)"
Ok. Can I close the issue?
zooba commentedon Jul 3, 2017
I wouldn't be opposed to seeing it tried again, but I have no strong opinion. I don't think this is a major performance bottleneck right now.
vstinner commentedon May 29, 2018
I failed to find the bandwidth to work on this issue since 2 years, so I just abandon this idea. However the performance benefit is non obvious.