gh-111968: Use per-thread freelists for generator in free-threading (gh-114189)

This commit is contained in:
Donghee Na 2024-01-19 03:15:00 +09:00 committed by GitHub
parent 2d3f6b56c5
commit 7fa511ba57
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 48 additions and 74 deletions

View file

@ -8,6 +8,8 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif
#include "pycore_freelist.h"
extern PyObject *_PyGen_yf(PyGenObject *);
extern void _PyGen_Finalize(PyObject *self);
@ -26,34 +28,7 @@ extern PyTypeObject _PyAsyncGenAThrow_Type;
/* runtime lifecycle */
extern void _PyAsyncGen_Fini(PyInterpreterState *);
/* other API */
#ifndef WITH_FREELISTS
// without freelists
# define _PyAsyncGen_MAXFREELIST 0
#endif
#ifndef _PyAsyncGen_MAXFREELIST
# define _PyAsyncGen_MAXFREELIST 80
#endif
struct _Py_async_gen_state {
#if _PyAsyncGen_MAXFREELIST > 0
/* Freelists boost performance 6-10%; they also reduce memory
fragmentation, as _PyAsyncGenWrappedValue and PyAsyncGenASend
are short-living objects that are instantiated for every
__anext__() call. */
struct _PyAsyncGenWrappedValue* value_freelist[_PyAsyncGen_MAXFREELIST];
int value_numfree;
struct PyAsyncGenASend* asend_freelist[_PyAsyncGen_MAXFREELIST];
int asend_numfree;
#endif
};
extern void _PyAsyncGen_Fini(_PyFreeListState *);
#ifdef __cplusplus
}