8000 add more freelists · python/cpython@ea98fa1 · GitHub
[go: up one dir, main page]

Skip to content

Commit ea98fa1

Browse files
committed
add more freelists
1 parent 17100c0 commit ea98fa1

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

Include/internal/pycore_freelist.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ _Py_freelists_GET(void)
4040
#define _Py_FREELIST_POP(TYPE, NAME) \
4141
_Py_CAST(TYPE*, _PyFreeList_Pop(&_Py_freelists_GET()->NAME))
4242

43-
4443
// Pops a non-PyObject data structure from the freelist, returns NULL if the
4544
// freelist is empty.
4645
#define _Py_FREELIST_POP_MEM(NAME) \

Include/internal/pycore_freelist_state.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ extern "C" {
1818
# define Py_slices_MAXFREELIST 1
1919
# define Py_ranges_MAXFREELIST 10
2020
# define Py_shared_iters_MAXFREELIST 24
21+
# define Py_class_method_MAXFREELIST 10
2122
# define Py_contexts_MAXFREELIST 255
2223
# define Py_async_gens_MAXFREELIST 80
2324
# define Py_async_gen_asends_MAXFREELIST 80
@@ -46,6 +47,7 @@ struct _Py_freelists {
4647
struct _Py_freelist slices;
4748
struct _Py_freelist ranges;
4849
struct _Py_freelist shared_iters;
50+
struct _Py_freelist class_method;
4951
struct _Py_freelist contexts;
5052
struct _Py_freelist async_gens;
5153
struct _Py_freelist async_gen_asends;

Objects/classobject.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "Python.h"
44
#include "pycore_call.h" // _PyObject_VectorcallTstate()
55
#include "pycore_ceval.h" // _PyEval_GetBuiltin()
6+
#include "pycore_freelist.h"
67
#include "pycore_object.h"
78
#include "pycore_pyerrors.h"
89
#include "pycore_pystate.h" // _PyThreadState_GET()
@@ -112,9 +113,13 @@ PyMethod_New(PyObject *func, PyObject *self)
112113
PyErr_BadInternalCall();
113114
return NULL;
114115
}
115-
PyMethodObject *im = PyObject_GC_New(PyMethodObject, &PyMethod_Type);
116+
117+
PyMethodObject *im = _Py_FREELIST_POP(PyMethodObject, class_method);
116118
if (im == NULL) {
117-
return NULL;
119+
im = PyObject_GC_New(PyMethodObject, &PyMethod_Type);
120+
if (im == NULL) {
121+
return NULL;
122+
}
118123
}
119124
im->im_weakreflist = NULL;
120125
im->im_func = Py_NewRef(func);
@@ -245,7 +250,7 @@ method_dealloc(PyObject *self)
245250
PyObject_ClearWeakRefs((PyObject *)im);
246251
Py_DECREF(im->im_func);
247252
Py_XDECREF(im->im_self);
248-
PyObject_GC_Del(im);
253+
_Py_FREELIST_FREE(class_method, (PyObject *)im, PyObject_GC_Del);
249254
}
250255

251256
static PyObject *

Objects/iterobject.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "pycore_abstract.h" // _PyObject_HasLen()
55
#include "pycore_call.h" // _PyObject_CallNoArgs()
66
#include "pycore_ceval.h" // _PyEval_GetBuiltin()
7+
#include "pycore_freelist.h" // _Py_FREELIST_PUSH(), _Py_FREELIST_POP()
78
#include "pycore_object.h" // _PyObject_GC_TRACK()
89

910
typedef struct {
@@ -21,9 +22,16 @@ PySeqIter_New(PyObject *seq)
2122
PyErr_BadInternalCall();
2223
return NULL;
2324
}
24-
it = PyObject_GC_New(seqiterobject, &PySeqIter_Type);
25-
if (it == NULL)
26-
return NULL;
25+
26+
it = _Py_FREELIST_POP(seqiterobject, shared_iters);
27+
if (it == NULL) {
28+
it = PyObject_GC_New(seqiterobject, &PySeqIter_Type);
29+
if (it == NULL)
30+
return NULL;
31+
}
32+
else {
33+
Py_SET_TYPE(it, &PySeqIter_Type);
34+
}
2735
it->it_index = 0;
2836
it->it_seq = Py_NewRef(seq);
2937
_PyObject_GC_TRACK(it);
@@ -35,7 +43,8 @@ iter_dealloc(seqiterobject *it)
3543
{
3644
_PyObject_GC_UNTRACK(it);
3745
Py_XDECREF(it->it_seq);
38-
PyObject_GC_Del(it);
46+
assert(sizeof(seqiterobject)==sizeof(_PyListIterObject));
47+
_Py_FREELIST_FREE(shared_iters, (PyObject *)it, PyObject_GC_Del);
3948
}
4049

4150
static int

Objects/typeobject.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "pycore_code.h" // CO_FAST_FREE
77
#include "pycore_dict.h" // _PyDict_KeysSize()
88
#include "pycore_frame.h" // _PyInterpreterFrame
9-
#include "pycore_freelist.h" // _Py_FREELIST_FREE(), _Py_FREELIST_POP()
109
#include "pycore_lock.h" // _PySeqLock_*
1110
#include "pycore_long.h" // _PyLong_IsNegative(), _PyLong_GetOne()
1211
#include "pycore_memoryobject.h" // _PyMemoryView_FromBufferProc()

0 commit comments

Comments
 (0)
0