]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-123990: Good bye WITH_FREELISTS macro (gh-124358)
authorDonghee Na <donghee.na@python.org>
Tue, 24 Sep 2024 01:28:59 +0000 (18:28 -0700)
committerGitHub <noreply@github.com>
Tue, 24 Sep 2024 01:28:59 +0000 (01:28 +0000)
16 files changed:
Doc/using/configure.rst
Doc/whatsnew/3.11.rst
Include/internal/pycore_freelist.h
Include/internal/pycore_freelist_state.h
Lib/test/pythoninfo.py
Lib/test/test_sys.py
Misc/NEWS.d/next/Build/2024-09-23-11-27-25.gh-issue-123990.d6HrYC.rst [new file with mode: 0644]
Objects/dictobject.c
Objects/floatobject.c
Objects/listobject.c
Objects/object.c
Objects/tupleobject.c
PC/pyconfig.h.in
configure
configure.ac
pyconfig.h.in

index 10adf744c7ff521b92e6fe389417ca67f2944fd1..4976418ba33cf868af2d23a501de38d19349cab4 100644 (file)
@@ -183,12 +183,6 @@ General Options
 
    See :envvar:`PYTHONCOERCECLOCALE` and the :pep:`538`.
 
-.. option:: --without-freelists
-
-   Disable all freelists except the empty tuple singleton.
-
-   .. versionadded:: 3.11
-
 .. option:: --with-platlibdir=DIRNAME
 
    Python library directory name (default is ``lib``).
index d59f24406c94835e16d6fb6bef6c92e958ce1932..e5c6d7cd3085040d94d7e9c2531e8253fa5a4c1c 100644 (file)
@@ -2168,7 +2168,7 @@ Build Changes
   (Contributed by Donghee Na and Brett Holman in :issue:`44340`.)
 
 * Freelists for object structs can now be disabled. A new :program:`configure`
-  option :option:`--without-freelists` can be used to disable all freelists
+  option ``--without-freelists`` can be used to disable all freelists
   except empty tuple singleton.
   (Contributed by Christian Heimes in :issue:`45522`.)
 
index 1ac0fed584ebd9adb060653f9ac6d12129d67e37..da2d7bf6ae13939b23c8d512f2017c6e530ed4a6 100644 (file)
@@ -28,13 +28,6 @@ _Py_freelists_GET(void)
 #endif
 }
 
-#ifndef WITH_FREELISTS
-#define _Py_FREELIST_FREE(NAME, op, freefunc) freefunc(op)
-#define _Py_FREELIST_PUSH(NAME, op, limit) (0)
-#define _Py_FREELIST_POP(TYPE, NAME) (NULL)
-#define _Py_FREELIST_POP_MEM(NAME) (NULL)
-#define _Py_FREELIST_SIZE(NAME) (0)
-#else
 // Pushes `op` to the freelist, calls `freefunc` if the freelist is full
 #define _Py_FREELIST_FREE(NAME, op, freefunc) \
     _PyFreeList_Free(&_Py_freelists_GET()->NAME, _PyObject_CAST(op), \
@@ -108,7 +101,6 @@ _PyFreeList_PopMem(struct _Py_freelist *fl)
     }
     return op;
 }
-#endif
 
 extern void _PyObject_ClearFreeLists(struct _Py_freelists *freelists, int is_finalization);
 
index e8df784bcba06e817f9928e269d6b7045114d6fe..762c583ce94e9a08eb43d9c43eb4071cbe992204 100644 (file)
@@ -8,8 +8,6 @@ extern "C" {
 #  error "this header requires Py_BUILD_CORE define"
 #endif
 
-#ifdef WITH_FREELISTS
-// with freelists
 #  define PyTuple_MAXSAVESIZE 20     // Largest tuple to save on freelist
 #  define Py_tuple_MAXFREELIST 2000  // Maximum number of tuples of each size to save
 #  define Py_lists_MAXFREELIST 80
@@ -22,9 +20,6 @@ extern "C" {
 #  define Py_async_gen_asends_MAXFREELIST 80
 #  define Py_futureiters_MAXFREELIST 255
 #  define Py_object_stack_chunks_MAXFREELIST 4
-#else
-#  define PyTuple_MAXSAVESIZE 0
-#endif
 
 // A generic freelist of either PyObjects or other data structures.
 struct _Py_freelist {
@@ -38,7 +33,6 @@ struct _Py_freelist {
 };
 
 struct _Py_freelists {
-#ifdef WITH_FREELISTS
     struct _Py_freelist floats;
     struct _Py_freelist tuples[PyTuple_MAXSAVESIZE];
     struct _Py_freelist lists;
@@ -50,9 +44,6 @@ struct _Py_freelists {
     struct _Py_freelist async_gen_asends;
     struct _Py_freelist futureiters;
     struct _Py_freelist object_stack_chunks;
-#else
-    char _unused;  // Empty structs are not allowed.
-#endif
 };
 
 #ifdef __cplusplus
index d928e002ebda109739181b9b0ab44fc41faae485..05a28bda2d38ba4051d3a232c978007555605384 100644 (file)
@@ -553,7 +553,6 @@ def collect_sysconfig(info_add):
     for name in (
         'WITH_DOC_STRINGS',
         'WITH_DTRACE',
-        'WITH_FREELISTS',
         'WITH_MIMALLOC',
         'WITH_PYMALLOC',
         'WITH_VALGRIND',
index 77009648bd26ed3cb71d76b22f00b921fdee4eb3..9689ef8e96e072ec17b7c34a1bbd226e5b52649a 100644 (file)
@@ -1042,14 +1042,10 @@ class SysModuleTest(unittest.TestCase):
         # Output of sys._debugmallocstats() depends on configure flags.
         # The sysconfig vars are not available on Windows.
         if sys.platform != "win32":
-            with_freelists = sysconfig.get_config_var("WITH_FREELISTS")
             with_pymalloc = sysconfig.get_config_var("WITH_PYMALLOC")
-            if with_freelists:
-                self.assertIn(b"free PyDictObjects", err)
+            self.assertIn(b"free PyDictObjects", err)
             if with_pymalloc:
                 self.assertIn(b'Small block threshold', err)
-            if not with_freelists and not with_pymalloc:
-                self.assertFalse(err)
 
         # The function has no parameter
         self.assertRaises(TypeError, sys._debugmallocstats, True)
diff --git a/Misc/NEWS.d/next/Build/2024-09-23-11-27-25.gh-issue-123990.d6HrYC.rst b/Misc/NEWS.d/next/Build/2024-09-23-11-27-25.gh-issue-123990.d6HrYC.rst
new file mode 100644 (file)
index 0000000..2b4f993
--- /dev/null
@@ -0,0 +1 @@
+Remove ``WITH_FREELISTS`` macro and ``--without-freelists`` build configuration
index db21961bad266bc7dc09f76e6b181014f98751e7..f38ab1b2865e995da2ec0e0f977e0535b8958b57 100644 (file)
@@ -406,14 +406,12 @@ unicode_get_hash(PyObject *o)
 void
 _PyDict_DebugMallocStats(FILE *out)
 {
-#ifdef WITH_FREELISTS
     _PyDebugAllocatorStats(out, "free PyDictObject",
                            _Py_FREELIST_SIZE(dicts),
                            sizeof(PyDictObject));
     _PyDebugAllocatorStats(out, "free PyDictKeysObject",
                            _Py_FREELIST_SIZE(dictkeys),
                            sizeof(PyDictKeysObject));
-#endif
 }
 
 #define DK_MASK(dk) (DK_SIZE(dk)-1)
index 68fd3e5463295075d5e114a8d3e88699a24af85d..dc3d8a3e5d0f4b76c53a9a00f56a33c3bfc3ffbb 100644 (file)
@@ -235,15 +235,10 @@ static void
 float_dealloc(PyObject *op)
 {
     assert(PyFloat_Check(op));
-#ifdef WITH_FREELISTS
-    if (PyFloat_CheckExact(op)) {
+    if (PyFloat_CheckExact(op))
         _PyFloat_ExactDealloc(op);
-    }
     else
-#endif
-    {
         Py_TYPE(op)->tp_free(op);
-    }
 }
 
 double
@@ -1975,12 +1970,10 @@ _PyFloat_FiniType(PyInterpreterState *interp)
 void
 _PyFloat_DebugMallocStats(FILE *out)
 {
-#ifdef WITH_FREELISTS
     _PyDebugAllocatorStats(out,
                            "free PyFloatObject",
                            _Py_FREELIST_SIZE(floats),
                            sizeof(PyFloatObject));
-#endif
 }
 
 
index 067d1a18d3bb75e390d44ab12d7936d8d71de140..8abe15d6674140cc4d279dee735a8ae70e6f1804 100644 (file)
@@ -200,12 +200,10 @@ list_preallocate_exact(PyListObject *self, Py_ssize_t size)
 void
 _PyList_DebugMallocStats(FILE *out)
 {
-#ifdef WITH_FREELISTS
     _PyDebugAllocatorStats(out,
                            "free PyListObject",
                             _Py_FREELIST_SIZE(lists),
                            sizeof(PyListObject));
-#endif
 }
 
 PyObject *
index 4b8b6c29266812874b8b8d91b23e907fdd4f78b2..bc63b8120a516037e6aaef3e603ffb7b8e0cfdf8 100644 (file)
@@ -816,7 +816,6 @@ PyObject_Bytes(PyObject *v)
     return PyBytes_FromObject(v);
 }
 
-#ifdef WITH_FREELISTS
 static void
 clear_freelist(struct _Py_freelist *freelist, int is_finalization,
                freefunc dofree)
@@ -841,12 +840,9 @@ free_object(void *obj)
     Py_DECREF(tp);
 }
 
-#endif
-
 void
 _PyObject_ClearFreeLists(struct _Py_freelists *freelists, int is_finalization)
 {
-#ifdef WITH_FREELISTS
     // In the free-threaded build, freelists are per-PyThreadState and cleared in PyThreadState_Clear()
     // In the default build, freelists are per-interpreter and cleared in finalize_interp_types()
     clear_freelist(&freelists->floats, is_finalization, free_object);
@@ -866,7 +862,6 @@ _PyObject_ClearFreeLists(struct _Py_freelists *freelists, int is_finalization)
         // stacks during GC, so emptying the free-list is counterproductive.
         clear_freelist(&freelists->object_stack_chunks, 1, PyMem_RawFree);
     }
-#endif
 }
 
 /*
index bd6e568191167af45ed2a1bbd13e8de089261c50..f14f10ab9c0a46f3d698b19c9a768d5e3bbfff13 100644 (file)
@@ -1146,7 +1146,6 @@ maybe_freelist_push(PyTupleObject *op)
 void
 _PyTuple_DebugMallocStats(FILE *out)
 {
-#ifdef WITH_FREELISTS
     for (int i = 0; i < PyTuple_MAXSAVESIZE; i++) {
         int len = i + 1;
         char buf[128];
@@ -1155,5 +1154,4 @@ _PyTuple_DebugMallocStats(FILE *out)
         _PyDebugAllocatorStats(out, buf, _Py_FREELIST_SIZE(tuples[i]),
                                _PyObject_VAR_SIZE(&PyTuple_Type, len));
     }
-#endif
 }
index f44e41c2e72f849c779ca2a96c7de91e3a45113e..503f3193e2803ebe2d60707442fab0cc70c701a0 100644 (file)
@@ -531,9 +531,6 @@ Py_NO_ENABLE_SHARED to find out.  Also support MS_NO_COREDLL for b/w compat */
 /* Define if you want to compile in mimalloc memory allocator. */
 #define WITH_MIMALLOC 1
 
-/* Define if you want to compile in object freelists optimization */
-#define WITH_FREELISTS 1
-
 /* Define if you have clock.  */
 /* #define HAVE_CLOCK */
 
index 56b923b764ec46683ca26680308f9057c592273e..0cc73e4e66552d13c4f328aaa30b2a6bd749f954 100755 (executable)
--- a/configure
+++ b/configure
@@ -1116,7 +1116,6 @@ enable_ipv6
 with_doc_strings
 with_mimalloc
 with_pymalloc
-with_freelists
 with_c_locale_coercion
 with_valgrind
 with_dtrace
@@ -1918,7 +1917,6 @@ Optional Packages:
   --with-mimalloc         build with mimalloc memory allocator (default is yes
                           if C11 stdatomic.h is available.)
   --with-pymalloc         enable specialized mallocs (default is yes)
-  --with-freelists        enable object freelists (default is yes)
   --with-c-locale-coercion
                           enable C locale coercion to a UTF-8 based locale
                           (default is yes)
 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $with_pymalloc" >&5
 printf "%s\n" "$with_pymalloc" >&6; }
 
-# Check whether objects such as float, tuple and dict are using
-# freelists to optimization memory allocation.
-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for --with-freelists" >&5
-printf %s "checking for --with-freelists... " >&6; }
-
-# Check whether --with-freelists was given.
-if test ${with_freelists+y}
-then :
-  withval=$with_freelists;
-fi
-
-
-if test -z "$with_freelists"
-then
-    with_freelists="yes"
-fi
-if test "$with_freelists" != "no"
-then
-
-printf "%s\n" "#define WITH_FREELISTS 1" >>confdefs.h
-
-fi
-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $with_freelists" >&5
-printf "%s\n" "$with_freelists" >&6; }
-
 # Check for --with-c-locale-coercion
 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for --with-c-locale-coercion" >&5
 printf %s "checking for --with-c-locale-coercion... " >&6; }
index c4df726cd6a8aee72bc847b1db993b900c880dcc..1864e94ace92432b342279a7df02dc5bb2040880 100644 (file)
@@ -4977,24 +4977,6 @@ then
 fi
 AC_MSG_RESULT([$with_pymalloc])
 
-# Check whether objects such as float, tuple and dict are using
-# freelists to optimization memory allocation.
-AC_MSG_CHECKING([for --with-freelists])
-AC_ARG_WITH(
-  [freelists],
-  [AS_HELP_STRING([--with-freelists], [enable object freelists (default is yes)])])
-
-if test -z "$with_freelists"
-then
-    with_freelists="yes"
-fi
-if test "$with_freelists" != "no"
-then
-    AC_DEFINE([WITH_FREELISTS], [1],
-     [Define if you want to compile in object freelists optimization])
-fi
-AC_MSG_RESULT([$with_freelists])
-
 # Check for --with-c-locale-coercion
 AC_MSG_CHECKING([for --with-c-locale-coercion])
 AC_ARG_WITH(
index a5946f3547b35cf805188e0ec1a7bae9b740a9bd..7f02603e26f5d09c21e6a725c46abae0e1deb906 100644 (file)
 /* Define to build the readline module against libedit. */
 #undef WITH_EDITLINE
 
-/* Define if you want to compile in object freelists optimization */
-#undef WITH_FREELISTS
-
 /* Define to 1 if libintl is needed for locale functions. */
 #undef WITH_LIBINTL