diff options
author | Raymond Hettinger <python@rcn.com> | 2013-09-08 03:26:50 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2013-09-08 03:26:50 (GMT) |
commit | 8f8839e10adc4d2b89ca26642c89c22382b1ce2f (patch) | |
tree | 16ae41cafec99a8920e3a554ac62e82d68ba35fd /Objects | |
parent | ff6382b40dfe6c0c978f25f027a72ac91c5449a6 (diff) | |
download | cpython-8f8839e10adc4d2b89ca26642c89c22382b1ce2f.zip cpython-8f8839e10adc4d2b89ca26642c89c22382b1ce2f.tar.gz cpython-8f8839e10adc4d2b89ca26642c89c22382b1ce2f.tar.bz2 |
Remove the freelist scheme for setobjects.
The setobject freelist was consuming memory but not providing much value.
Even when a freelisted setobject was available, most of the setobject
fields still needed to be initialized and the small table still required
a memset(). This meant that the custom freelisting scheme for sets was
providing almost no incremental benefit over the default Python freelist
scheme used by _PyObject_Malloc() in Objects/obmalloc.c.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/object.c | 1 | ||||
-rw-r--r-- | Objects/setobject.c | 55 |
2 files changed, 8 insertions, 48 deletions
diff --git a/Objects/object.c b/Objects/object.c index 693d8c7..8018c6a 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -1955,7 +1955,6 @@ _PyObject_DebugTypeStats(FILE *out) _PyFrame_DebugMallocStats(out); _PyList_DebugMallocStats(out); _PyMethod_DebugMallocStats(out); - _PySet_DebugMallocStats(out); _PyTuple_DebugMallocStats(out); } diff --git a/Objects/setobject.c b/Objects/setobject.c index 362273a..e2cb666 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -57,13 +57,6 @@ PyObject *_PySet_Dummy = dummy; INIT_NONZERO_SET_SLOTS(so); \ } while(0) -/* Reuse scheme to save calls to malloc, free, and memset */ -#ifndef PySet_MAXFREELIST -#define PySet_MAXFREELIST 80 -#endif -static PySetObject *free_list[PySet_MAXFREELIST]; -static int numfree = 0; - /* ======================================================================== */ /* ======= Begin logic for probing the hash table ========================= */ @@ -565,10 +558,7 @@ set_dealloc(PySetObject *so) } if (so->table != so->smalltable) PyMem_DEL(so->table); - if (numfree < PySet_MAXFREELIST && PyAnySet_CheckExact(so)) - free_list[numfree++] = so; - else - Py_TYPE(so)->tp_free(so); + Py_TYPE(so)->tp_free(so); Py_TRASHCAN_SAFE_END(so) } @@ -1023,22 +1013,12 @@ make_new_set(PyTypeObject *type, PyObject *iterable) PySetObject *so = NULL; /* create PySetObject structure */ - if (numfree && - (type == &PySet_Type || type == &PyFrozenSet_Type)) { - so = free_list[--numfree]; - assert (so != NULL && PyAnySet_CheckExact(so)); - Py_TYPE(so) = type; - _Py_NewReference((PyObject *)so); - EMPTY_TO_MINSIZE(so); - PyObject_GC_Track(so); - } else { - so = (PySetObject *)type->tp_alloc(type, 0); - if (so == NULL) - return NULL; - /* tp_alloc has already zeroed the structure */ - assert(so->table == NULL && so->fill == 0 && so->used == 0); - INIT_NONZERO_SET_SLOTS(so); - } + so = (PySetObject *)type->tp_alloc(type, 0); + if (so == NULL) + return NULL; + /* tp_alloc has already zeroed the structure */ + assert(so->table == NULL && so->fill == 0 && so->used == 0); + INIT_NONZERO_SET_SLOTS(so); so->lookup = set_lookkey_unicode; so->weakreflist = NULL; @@ -1103,34 +1083,15 @@ frozenset_new(PyTypeObject *type, PyObject *args, PyObject *kwds) int PySet_ClearFreeList(void) { - int freelist_size = numfree; - PySetObject *so; - - while (numfree) { - numfree--; - so = free_list[numfree]; - PyObject_GC_Del(so); - } - return freelist_size; + return 0; } void PySet_Fini(void) { - PySet_ClearFreeList(); Py_CLEAR(emptyfrozenset); } -/* Print summary info about the state of the optimized allocator */ -void -_PySet_DebugMallocStats(FILE *out) -{ - _PyDebugAllocatorStats(out, - "free PySetObject", - numfree, sizeof(PySetObject)); -} - - static PyObject * set_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { |