[issue46799] ShareableList memory bloat and performance improvement
Ting-Che Lin
report at bugs.python.org
Sun Feb 27 03:44:39 EST 2022
Ting-Che Lin <lintingche2012 at gmail.com> added the comment:
So I wrote a patch for this issue and published submitted a MR. When I was working on the patch, I realized that there is another issue related to how string and byte array size alignment is calculated. As seen here: https://github.com/python/cpython/blob/3.10/Lib/multiprocessing/shared_memory.py#L303.
>>> from multiprocessing.shared_memory import ShareableList
>>> s_list = ShareableList(["12345678"])
>>> s_list.format
'16s'
I changed the calculation of
self._alignment * (len(item) // self._alignment + 1),
to
self._alignment * max(1, (len(item) - 1) // self._alignment + 1)
With the patch, this will give
>>> from multiprocessing.shared_memory import ShareableList
>>> s_list = ShareableList(["12345678"])
>>> s_list.format
'8s'
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46799>
_______________________________________
More information about the Python-bugs-list
mailing list