Message225465
dtoa.c has an optimized memory allocator for performances: it uses a short pool of 2304 doubles (18 KB) to avoid calling malloc/free. Comment in dtoa.c:
/* Memory management: memory is allocated from, and returned to, Kmax+1 pools
of memory, where pool k (0 <= k <= Kmax) is for Bigints b with b->maxwds ==
1 << k. These pools are maintained as linked lists, with freelist[k]
pointing to the head of the list for pool k.
On allocation, if there's no free slot in the appropriate pool, MALLOC is
called to get more memory. This memory is not returned to the system until
Python quits. There's also a private memory pool that's allocated from
in preference to using MALLOC.
For Bigints with more than (1 << Kmax) digits (which implies at least 1233
decimal digits), memory is directly allocated using MALLOC, and freed using
FREE.
XXX: it would be easy to bypass this memory-management system and
translate each call to Balloc into a call to PyMem_Malloc, and each
Bfree to PyMem_Free. Investigate whether this has any significant
performance on impact. */
Python already has such memory pool: PyObject_Malloc(). I propose to reuse it. It avoids wasting memory "until Python quits" just to optimize dtoa.c.
dtoa.c memory pool is only used for allocations smaller than 68 bytes (on 64 bits system, Kmax=7). PyObject_Malloc() is optimized for allocations smaller than 513 bytes, so it's ok.
See also the issue #7632. |
|
Date |
User |
Action |
Args |
2014-08-17 19:55:29 | vstinner | set | recipients:
+ vstinner, mark.dickinson, skrah |
2014-08-17 19:55:29 | vstinner | set | messageid: <1408305329.63.0.21484400673.issue22222@psf.upfronthosting.co.za> |
2014-08-17 19:55:29 | vstinner | link | issue22222 messages |
2014-08-17 19:55:29 | vstinner | create | |
|