diff options
author | Raymond Hettinger <python@rcn.com> | 2004-02-13 11:36:39 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2004-02-13 11:36:39 (GMT) |
commit | 4bb9540dd6eddaf60b908796c2412696a8870bd1 (patch) | |
tree | f2989cf9d6895dec915f307b40cd6e9a276991ce /Include | |
parent | 4a8d42f73f9767622f32468c02cefe616ccb34cf (diff) | |
download | cpython-4bb9540dd6eddaf60b908796c2412696a8870bd1.zip cpython-4bb9540dd6eddaf60b908796c2412696a8870bd1.tar.gz cpython-4bb9540dd6eddaf60b908796c2412696a8870bd1.tar.bz2 |
* Optimized list appends and pops by making fewer calls the underlying system
realloc(). This is achieved by tracking the overallocation size in a new
field and using that information to skip calls to realloc() whenever
possible.
* Simplified and tightened the amount of overallocation. For larger lists,
this overallocates by 1/8th (compared to the previous scheme which ranged
between 1/4th to 1/32nd over-allocation). For smaller lists (n<6), the
maximum overallocation is one byte (formerly it could be upto eight bytes).
This saves memory in applications with large numbers of small lists.
* Eliminated the NRESIZE macro in favor of a new, static list_resize function
that encapsulates the resizing logic. Coverting this back to macro would
give a small (under 1%) speed-up. This was too small to warrant the loss
of readability, maintainability, and de-coupling.
* Some functions using NRESIZE had grown unnecessarily complex in their
efforts to bend to the macro's calling pattern. With the new list_resize
function in place, those other functions could be simplified. That is
being saved for a separate patch.
* The ob_item==NULL check could be eliminated from the new list_resize
function. This would entail finding each piece of code that sets ob_item
to NULL and adding a new line to invalidate the overallocation tracking
field. Rather than impose a new requirement on other pieces of list code,
it was preferred to leave the NULL check in place and retain the benefits
of decoupling, maintainability and information hiding (only PyList_New()
and list_sort() need to know about the new field). This approach also
reduces the odds of breaking an extension module.
(Collaborative effort by Raymond Hettinger, Hye-Shik Chang, Tim Peters,
and Armin Rigo.)
Diffstat (limited to 'Include')
-rw-r--r-- | Include/listobject.h | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/Include/listobject.h b/Include/listobject.h index 14ed72e..6221b80 100644 --- a/Include/listobject.h +++ b/Include/listobject.h @@ -22,6 +22,7 @@ extern "C" { typedef struct { PyObject_VAR_HEAD PyObject **ob_item; + int allocated; } PyListObject; PyAPI_DATA(PyTypeObject) PyList_Type; |