cpython/Include/cpython
Eric Snow 2c1e2583fd
bpo-43693: Add new internal code objects fields: co_fastlocalnames and co_fastlocalkinds. (gh-26388)
A number of places in the code base (notably ceval.c and frameobject.c) rely on mapping variable names to indices in the frame "locals plus" array (AKA fast locals), and thus opargs.  Currently the compiler indirectly encodes that information on the code object as the tuples co_varnames, co_cellvars, and co_freevars.  At runtime the dependent code must calculate the proper mapping from those, which isn't ideal and impacts performance-sensitive sections.  This is something we can easily address in the compiler instead.

This change addresses the situation by replacing internal use of co_varnames, etc. with a single combined tuple of names in locals-plus order, along with a minimal array mapping each to its kind (local vs. cell vs. free).  These two new PyCodeObject fields, co_fastlocalnames and co_fastllocalkinds, are not exposed to Python code for now, but co_varnames, etc. are still available with the same values as before (though computed lazily).

Aside from the (mild) performance impact, there are a number of other benefits:

* there's now a clear, direct relationship between locals-plus and variables
* code that relies on the locals-plus-to-name mapping is simpler
* marshaled code objects are smaller and serialize/de-serialize faster

Also note that we can take this approach further by expanding the possible values in co_fastlocalkinds to include specific argument types (e.g. positional-only, kwargs).  Doing so would allow further speed-ups in _PyEval_MakeFrameVector(), which is where args get unpacked into the locals-plus array.  It would also allow us to shrink marshaled code objects even further.

https://bugs.python.org/issue43693
2021-06-03 10:28:27 -06:00
..
abstract.h bpo-40522: Replace PyThreadState_GET() with PyThreadState_Get() (GH-24575) 2021-02-19 13:21:51 +01:00
bytearrayobject.h bpo-35134: Add Include/cpython/bytesobject.h file (GH-18494) 2020-02-12 23:54:31 +01:00
bytesobject.h bpo-42431: Fix outdated bytes comments (GH-23458) 2020-12-03 12:46:16 +02:00
ceval.h bpo-37146: Move _PyEval_DeactivateOpCache() to the internal C API (GH-24786) 2021-03-08 22:56:37 +01:00
code.h bpo-43693: Add new internal code objects fields: co_fastlocalnames and co_fastlocalkinds. (gh-26388) 2021-06-03 10:28:27 -06:00
compile.h bpo-43244: Add pycore_compile.h header file (GH-25000) 2021-03-24 00:51:50 +01:00
dictobject.h bpo-44206: Add a version number to dictionary keys (GH-26333) 2021-05-28 09:54:10 +01:00
fileobject.h bpo-41986: Add Py_FileSystemDefaultEncodeErrors and Py_UTF8Mode back to limited API (GH-22621) 2020-10-10 17:09:45 +03:00
fileutils.h bpo-30555: Fix WindowsConsoleIO fails in the presence of fd redirection (GH-1927) 2021-04-23 23:00:27 +01:00
frameobject.h bpo-44032: Move data stack to thread from FrameObject. (GH-26076) 2021-05-21 10:57:35 +01:00
import.h bpo-41994: Fix refcount issues in Python/import.c (GH-22632) 2021-01-12 15:43:32 +01:00
initconfig.h bpo-43510: Implement PEP 597 opt-in EncodingWarning. (GH-19481) 2021-03-29 12:28:14 +09:00
interpreteridobject.h bpo-39583: Remove superfluous "extern C" bits from Include/cpython/*.h (GH-18413) 2020-06-01 20:35:56 +02:00
listobject.h bpo-30459: Cast the result of PyList_SET_ITEM() to void (GH-19975) 2020-12-05 11:34:51 +01:00
methodobject.h bpo-38787: Add PyCFunction_CheckExact() macro for exact type checks (GH-20024) 2020-05-12 07:12:41 -07:00
object.h bpo-43908: Document Static Types in the C API (GH-25710) 2021-04-29 10:26:34 +02:00
objimpl.h bpo-42208: Pass tstate to _PyGC_CollectNoFail() (GH-23038) 2020-10-30 17:00:00 +01:00
odictobject.h bpo-35134: Move non-limited C API files to Include/cpython/ (GH-24561) 2021-02-19 15:55:46 +01:00
picklebufobject.h bpo-35134: Move non-limited C API files to Include/cpython/ (GH-24561) 2021-02-19 15:55:46 +01:00
pyctype.h bpo-43816: Add extern "C" to Include/cpython/pyctype.h (GH-25365) 2021-04-13 13:27:21 +02:00
pydebug.h bpo-35134: Move non-limited C API files to Include/cpython/ (GH-24561) 2021-02-19 15:55:46 +01:00
pyerrors.h bpo-44094: Remove deprecated PyErr_ APIs. (GH-26011) 2021-05-13 13:45:26 -07:00
pyfpe.h bpo-35134: Move non-limited C API files to Include/cpython/ (GH-24561) 2021-02-19 15:55:46 +01:00
pylifecycle.h bpo-43795: Remove Py_FrozenMain from the Limited API & Stable ABI (GH-26241) 2021-05-25 04:42:03 -07:00
pymem.h bpo-43795: PEP-652: Clean up the stable ABI/limited API (GH-25482) 2021-04-23 14:17:58 +02:00
pystate.h bpo-43879: Add native_thread_id field to PyThreadState (GH-25458) 2021-05-26 16:40:14 +02:00
pythonrun.h bpo-43868: Remove PyOS_ReadlineFunctionPointer from the stable ABI list (GH-25442) 2021-04-23 14:23:38 +02:00
pytime.h bpo-35134, Include: Move pytime.h to cpython/pytime.h (GH-23988) 2021-02-16 13:04:38 +01:00
sysmodule.h bpo-39583: Remove superfluous "extern C" bits from Include/cpython/*.h (GH-18413) 2020-06-01 20:35:56 +02:00
traceback.h bpo-39583: Remove superfluous "extern C" bits from Include/cpython/*.h (GH-18413) 2020-06-01 20:35:56 +02:00
tupleobject.h bpo-30459: Cast the result of PyList_SET_ITEM() to void (GH-19975) 2020-12-05 11:34:51 +01:00
unicodeobject.h bpo-44029: Remove Py_UNICODE APIs (GH-25881) 2021-05-07 15:58:29 +09:00