Skip to content

Commit ad7c778

Browse files
authored
gh-123990: Good bye WITH_FREELISTS macro (gh-124358)
1 parent be76e3f commit ad7c778

16 files changed

+4
-100
lines changed

Doc/using/configure.rst

-6
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,6 @@ General Options
183183

184184
See :envvar:`PYTHONCOERCECLOCALE` and the :pep:`538`.
185185

186-
.. option:: --without-freelists
187-
188-
Disable all freelists except the empty tuple singleton.
189-
190-
.. versionadded:: 3.11
191-
192186
.. option:: --with-platlibdir=DIRNAME
193187

194188
Python library directory name (default is ``lib``).

Doc/whatsnew/3.11.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -2168,7 +2168,7 @@ Build Changes
21682168
(Contributed by Donghee Na and Brett Holman in :issue:`44340`.)
21692169

21702170
* Freelists for object structs can now be disabled. A new :program:`configure`
2171-
option :option:`--without-freelists` can be used to disable all freelists
2171+
option ``--without-freelists`` can be used to disable all freelists
21722172
except empty tuple singleton.
21732173
(Contributed by Christian Heimes in :issue:`45522`.)
21742174

Include/internal/pycore_freelist.h

-8
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ _Py_freelists_GET(void)
2828
#endif
2929
}
3030

31-
#ifndef WITH_FREELISTS
32-
#define _Py_FREELIST_FREE(NAME, op, freefunc) freefunc(op)
33-
#define _Py_FREELIST_PUSH(NAME, op, limit) (0)
34-
#define _Py_FREELIST_POP(TYPE, NAME) (NULL)
35-
#define _Py_FREELIST_POP_MEM(NAME) (NULL)
36-
#define _Py_FREELIST_SIZE(NAME) (0)
37-
#else
3831
// Pushes `op` to the freelist, calls `freefunc` if the freelist is full
3932
#define _Py_FREELIST_FREE(NAME, op, freefunc) \
4033
_PyFreeList_Free(&_Py_freelists_GET()->NAME, _PyObject_CAST(op), \
@@ -108,7 +101,6 @@ _PyFreeList_PopMem(struct _Py_freelist *fl)
108101
}
109102
return op;
110103
}
111-
#endif
112104

113105
extern void _PyObject_ClearFreeLists(struct _Py_freelists *freelists, int is_finalization);
114106

Include/internal/pycore_freelist_state.h

-9
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11-
#ifdef WITH_FREELISTS
12-
// with freelists
1311
# define PyTuple_MAXSAVESIZE 20 // Largest tuple to save on freelist
1412
# define Py_tuple_MAXFREELIST 2000 // Maximum number of tuples of each size to save
1513
# define Py_lists_MAXFREELIST 80
@@ -22,9 +20,6 @@ extern "C" {
2220
# define Py_async_gen_asends_MAXFREELIST 80
2321
# define Py_futureiters_MAXFREELIST 255
2422
# define Py_object_stack_chunks_MAXFREELIST 4
25-
#else
26-
# define PyTuple_MAXSAVESIZE 0
27-
#endif
2823

2924
// A generic freelist of either PyObjects or other data structures.
3025
struct _Py_freelist {
@@ -38,7 +33,6 @@ struct _Py_freelist {
3833
};
3934

4035
struct _Py_freelists {
41-
#ifdef WITH_FREELISTS
4236
struct _Py_freelist floats;
4337
struct _Py_freelist tuples[PyTuple_MAXSAVESIZE];
4438
struct _Py_freelist lists;
@@ -50,9 +44,6 @@ struct _Py_freelists {
5044
struct _Py_freelist async_gen_asends;
5145
struct _Py_freelist futureiters;
5246
struct _Py_freelist object_stack_chunks;
53-
#else
54-
char _unused; // Empty structs are not allowed.
55-
#endif
5647
};
5748

5849
#ifdef __cplusplus

Lib/test/pythoninfo.py

-1
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,6 @@ def collect_sysconfig(info_add):
553553
for name in (
554554
'WITH_DOC_STRINGS',
555555
'WITH_DTRACE',
556-
'WITH_FREELISTS',
557556
'WITH_MIMALLOC',
558557
'WITH_PYMALLOC',
559558
'WITH_VALGRIND',

Lib/test/test_sys.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -1042,14 +1042,10 @@ def test_debugmallocstats(self):
10421042
# Output of sys._debugmallocstats() depends on configure flags.
10431043
# The sysconfig vars are not available on Windows.
10441044
if sys.platform != "win32":
1045-
with_freelists = sysconfig.get_config_var("WITH_FREELISTS")
10461045
with_pymalloc = sysconfig.get_config_var("WITH_PYMALLOC")
1047-
if with_freelists:
1048-
self.assertIn(b"free PyDictObjects", err)
1046+
self.assertIn(b"free PyDictObjects", err)
10491047
if with_pymalloc:
10501048
self.assertIn(b'Small block threshold', err)
1051-
if not with_freelists and not with_pymalloc:
1052-
self.assertFalse(err)
10531049

10541050
# The function has no parameter
10551051
self.assertRaises(TypeError, sys._debugmallocstats, True)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove ``WITH_FREELISTS`` macro and ``--without-freelists`` build configuration

Objects/dictobject.c

-2
Original file line numberDiff line numberDiff line change
@@ -406,14 +406,12 @@ unicode_get_hash(PyObject *o)
406406
void
407407
_PyDict_DebugMallocStats(FILE *out)
408408
{
409-
#ifdef WITH_FREELISTS
410409
_PyDebugAllocatorStats(out, "free PyDictObject",
411410
_Py_FREELIST_SIZE(dicts),
412411
sizeof(PyDictObject));
413412
_PyDebugAllocatorStats(out, "free PyDictKeysObject",
414413
_Py_FREELIST_SIZE(dictkeys),
415414
sizeof(PyDictKeysObject));
416-
#endif
417415
}
418416

419417
#define DK_MASK(dk) (DK_SIZE(dk)-1)

Objects/floatobject.c

+1-8
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,10 @@ static void
235235
float_dealloc(PyObject *op)
236236
{
237237
assert(PyFloat_Check(op));
238-
#ifdef WITH_FREELISTS
239-
if (PyFloat_CheckExact(op)) {
238+
if (PyFloat_CheckExact(op))
240239
_PyFloat_ExactDealloc(op);
241-
}
242240
else
243-
#endif
244-
{
245241
Py_TYPE(op)->tp_free(op);
246-
}
247242
}
248243

249244
double
@@ -1975,12 +1970,10 @@ _PyFloat_FiniType(PyInterpreterState *interp)
19751970
void
19761971
_PyFloat_DebugMallocStats(FILE *out)
19771972
{
1978-
#ifdef WITH_FREELISTS
19791973
_PyDebugAllocatorStats(out,
19801974
"free PyFloatObject",
19811975
_Py_FREELIST_SIZE(floats),
19821976
sizeof(PyFloatObject));
1983-
#endif
19841977
}
19851978

19861979

Objects/listobject.c

-2
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,10 @@ list_preallocate_exact(PyListObject *self, Py_ssize_t size)
200200
void
201201
_PyList_DebugMallocStats(FILE *out)
202202
{
203-
#ifdef WITH_FREELISTS
204203
_PyDebugAllocatorStats(out,
205204
"free PyListObject",
206205
_Py_FREELIST_SIZE(lists),
207206
sizeof(PyListObject));
208-
#endif
209207
}
210208

211209
PyObject *

Objects/object.c

-5
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,6 @@ PyObject_Bytes(PyObject *v)
816816
return PyBytes_FromObject(v);
817817
}
818818

819-
#ifdef WITH_FREELISTS
820819
static void
821820
clear_freelist(struct _Py_freelist *freelist, int is_finalization,
822821
freefunc dofree)
@@ -841,12 +840,9 @@ free_object(void *obj)
841840
Py_DECREF(tp);
842841
}
843842

844-
#endif
845-
846843
void
847844
_PyObject_ClearFreeLists(struct _Py_freelists *freelists, int is_finalization)
848845
{
849-
#ifdef WITH_FREELISTS
850846
// In the free-threaded build, freelists are per-PyThreadState and cleared in PyThreadState_Clear()
851847
// In the default build, freelists are per-interpreter and cleared in finalize_interp_types()
852848
clear_freelist(&freelists->floats, is_finalization, free_object);
@@ -866,7 +862,6 @@ _PyObject_ClearFreeLists(struct _Py_freelists *freelists, int is_finalization)
866862
// stacks during GC, so emptying the free-list is counterproductive.
867863
clear_freelist(&freelists->object_stack_chunks, 1, PyMem_RawFree);
868864
}
869-
#endif
870865
}
871866

872867
/*

Objects/tupleobject.c

-2
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,6 @@ maybe_freelist_push(PyTupleObject *op)
11461146
void
11471147
_PyTuple_DebugMallocStats(FILE *out)
11481148
{
1149-
#ifdef WITH_FREELISTS
11501149
for (int i = 0; i < PyTuple_MAXSAVESIZE; i++) {
11511150
int len = i + 1;
11521151
char buf[128];
@@ -1155,5 +1154,4 @@ _PyTuple_DebugMallocStats(FILE *out)
11551154
_PyDebugAllocatorStats(out, buf, _Py_FREELIST_SIZE(tuples[i]),
11561155
_PyObject_VAR_SIZE(&PyTuple_Type, len));
11571156
}
1158-
#endif
11591157
}

PC/pyconfig.h.in

-3
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,6 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */
531531
/* Define if you want to compile in mimalloc memory allocator. */
532532
#define WITH_MIMALLOC 1
533533

534-
/* Define if you want to compile in object freelists optimization */
535-
#define WITH_FREELISTS 1
536-
537534
/* Define if you have clock. */
538535
/* #define HAVE_CLOCK */
539536

configure

-27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

-18
Original file line numberDiff line numberDiff line change
@@ -4977,24 +4977,6 @@ then
49774977
fi
49784978
AC_MSG_RESULT([$with_pymalloc])
49794979

4980-
# Check whether objects such as float, tuple and dict are using
4981-
# freelists to optimization memory allocation.
4982-
AC_MSG_CHECKING([for --with-freelists])
4983-
AC_ARG_WITH(
4984-
[freelists],
4985-
[AS_HELP_STRING([--with-freelists], [enable object freelists (default is yes)])])
4986-
4987-
if test -z "$with_freelists"
4988-
then
4989-
with_freelists="yes"
4990-
fi
4991-
if test "$with_freelists" != "no"
4992-
then
4993-
AC_DEFINE([WITH_FREELISTS], [1],
4994-
[Define if you want to compile in object freelists optimization])
4995-
fi
4996-
AC_MSG_RESULT([$with_freelists])
4997-
49984980
# Check for --with-c-locale-coercion
49994981
AC_MSG_CHECKING([for --with-c-locale-coercion])
50004982
AC_ARG_WITH(

pyconfig.h.in

-3
Original file line numberDiff line numberDiff line change
@@ -1901,9 +1901,6 @@
19011901
/* Define to build the readline module against libedit. */
19021902
#undef WITH_EDITLINE
19031903

1904-
/* Define if you want to compile in object freelists optimization */
1905-
#undef WITH_FREELISTS
1906-
19071904
/* Define to 1 if libintl is needed for locale functions. */
19081905
#undef WITH_LIBINTL
19091906

0 commit comments

Comments
 (0)