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``).
(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`.)
#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), \
}
return op;
}
-#endif
extern void _PyObject_ClearFreeLists(struct _Py_freelists *freelists, int is_finalization);
# 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
# 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 {
};
struct _Py_freelists {
-#ifdef WITH_FREELISTS
struct _Py_freelist floats;
struct _Py_freelist tuples[PyTuple_MAXSAVESIZE];
struct _Py_freelist lists;
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
for name in (
'WITH_DOC_STRINGS',
'WITH_DTRACE',
- 'WITH_FREELISTS',
'WITH_MIMALLOC',
'WITH_PYMALLOC',
'WITH_VALGRIND',
# 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)
--- /dev/null
+Remove ``WITH_FREELISTS`` macro and ``--without-freelists`` build configuration
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)
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
void
_PyFloat_DebugMallocStats(FILE *out)
{
-#ifdef WITH_FREELISTS
_PyDebugAllocatorStats(out,
"free PyFloatObject",
_Py_FREELIST_SIZE(floats),
sizeof(PyFloatObject));
-#endif
}
void
_PyList_DebugMallocStats(FILE *out)
{
-#ifdef WITH_FREELISTS
_PyDebugAllocatorStats(out,
"free PyListObject",
_Py_FREELIST_SIZE(lists),
sizeof(PyListObject));
-#endif
}
PyObject *
return PyBytes_FromObject(v);
}
-#ifdef WITH_FREELISTS
static void
clear_freelist(struct _Py_freelist *freelist, int is_finalization,
freefunc dofree)
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);
// stacks during GC, so emptying the free-list is counterproductive.
clear_freelist(&freelists->object_stack_chunks, 1, PyMem_RawFree);
}
-#endif
}
/*
void
_PyTuple_DebugMallocStats(FILE *out)
{
-#ifdef WITH_FREELISTS
for (int i = 0; i < PyTuple_MAXSAVESIZE; i++) {
int len = i + 1;
char buf[128];
_PyDebugAllocatorStats(out, buf, _Py_FREELIST_SIZE(tuples[i]),
_PyObject_VAR_SIZE(&PyTuple_Type, len));
}
-#endif
}
/* 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 */
with_doc_strings
with_mimalloc
with_pymalloc
-with_freelists
with_c_locale_coercion
with_valgrind
with_dtrace
--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; }
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(
/* 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