cpython/Include/internal
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
..
pycore_abstract.h bpo-40170: Add _PyIndex_Check() internal function (GH-19426) 2020-04-08 02:01:56 +02:00
pycore_accu.h bpo-36635: Change pyport.h for Py_BUILD_CORE_MODULE define (GH-12853) 2019-04-17 23:02:26 +02:00
pycore_asdl.h bpo-43244: Remove the pyarena.h header (GH-25007) 2021-03-24 02:23:01 +01:00
pycore_ast_state.h bpo-43892: Make match patterns explicit in the AST (GH-25585) 2021-04-28 22:58:44 -07:00
pycore_ast.h bpo-43892: Make match patterns explicit in the AST (GH-25585) 2021-04-28 22:58:44 -07:00
pycore_atomic_funcs.h bpo-39465: Add pycore_atomic_funcs.h header (GH-20766) 2020-12-23 03:41:08 +01:00
pycore_atomic.h bpo-39465: Add pycore_atomic_funcs.h header (GH-20766) 2020-12-23 03:41:08 +01:00
pycore_bitutils.h bpo-41617: Add _Py__has_builtin() macro (GH-23260) 2020-11-13 15:38:17 +01:00
pycore_blocks_output_buffer.h bpo-41486: Faster bz2/lzma/zlib via new output buffering (GH-21740) 2021-04-27 23:58:54 -07:00
pycore_bytes_methods.h bpo-35081: Move bytes_methods.h to the internal C API (GH-18492) 2020-02-12 22:32:34 +01:00
pycore_call.h bpo-38644: Add _PyObject_Call() (GH-17089) 2019-11-14 13:36:21 +01:00
pycore_ceval.h bpo-37146: Move _PyEval_DeactivateOpCache() to the internal C API (GH-24786) 2021-03-08 22:56:37 +01:00
pycore_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
pycore_compile.h bpo-42609: Check recursion depth in the AST validator and optimizer (GH-23744) 2021-04-25 13:38:00 +03:00
pycore_condvar.h Fix typo in block comment in Include/internal/pycore_condvar.h (GH-26457) 2021-06-01 18:30:05 -03:00
pycore_context.h bpo-43268: Pass interp rather than tstate to internal functions (GH-24580) 2021-02-19 15:10:45 +01:00
pycore_dtoa.h Revert "bpo-40521: Make dtoa bigint free list per-interpreter (GH-24821)" (GH-24964) 2021-03-22 11:58:59 +01:00
pycore_fileutils.h bpo-43667: Fix broken Unicode encoding in non-UTF locales on Solaris (GH-25096) 2021-04-30 15:21:42 +02:00
pycore_format.h bpo-42431: Fix outdated bytes comments (GH-23458) 2020-12-03 12:46:16 +02:00
pycore_frame.h bpo-44032: Move data stack to thread from FrameObject. (GH-26076) 2021-05-21 10:57:35 +01:00
pycore_gc.h bpo-43268: Pass interp rather than tstate to internal functions (GH-24580) 2021-02-19 15:10:45 +01:00
pycore_getopt.h bpo-36763: Cleanup precmdline in _PyCoreConfig_Read() (GH-13371) 2019-05-17 03:15:12 +02:00
pycore_gil.h bpo-38353: Cleanup includes in the internal C API (GH-16548) 2019-10-02 23:51:20 +02:00
pycore_hamt.h bpo-39573: Add Py_IS_TYPE() function (GH-18488) 2020-02-13 18:37:17 +01:00
pycore_hashtable.h bpo-40602: Write unit tests for _Py_hashtable_t (GH-20091) 2020-05-14 21:55:47 +02:00
pycore_import.h bpo-41994: Fix refcount issues in Python/import.c (GH-22632) 2021-01-12 15:43:32 +01:00
pycore_initconfig.h bpo-43510: Implement PEP 597 opt-in EncodingWarning. (GH-19481) 2021-03-29 12:28:14 +09:00
pycore_interp.h bpo-43977: Use tp_flags for collection matching (GH-25723) 2021-04-30 09:50:28 +01:00
pycore_list.h bpo-41078: Add pycore_list.h internal header file (GH-21057) 2020-06-22 17:39:32 +02:00
pycore_long.h bpo-43687: Py_Initialize() creates singletons earlier (GH-25147) 2021-04-02 15:28:13 +02:00
pycore_moduleobject.h bpo-40137: Add pycore_moduleobject.h internal header (GH-25507) 2021-04-22 00:52:52 +02:00
pycore_object.h bpo-43770: Refactor PyType_Ready() function (GH-25336) 2021-04-11 23:57:09 +02:00
pycore_parser.h bpo-43244: Remove parser_interface.h header file (GH-25001) 2021-03-24 01:29:09 +01:00
pycore_pathconfig.h bpo-29778: test_embed tests the path configuration (GH-21306) 2020-07-08 00:20:37 +02:00
pycore_pyarena.h bpo-43244: Remove the pyarena.h header (GH-25007) 2021-03-24 02:23:01 +01:00
pycore_pyerrors.h bpo-38530: Refactor and improve AttributeError suggestions (GH-25776) 2021-05-03 16:47:27 +01:00
pycore_pyhash.h bpo-36635: Change pyport.h for Py_BUILD_CORE_MODULE define (GH-12853) 2019-04-17 23:02:26 +02:00
pycore_pylifecycle.h bpo-43687: Py_Initialize() creates singletons earlier (GH-25147) 2021-04-02 15:28:13 +02:00
pycore_pymem.h bpo-44184: Fix subtype_dealloc() for freed type (GH-26274) 2021-05-21 19:19:54 +02:00
pycore_pystate.h bpo-44032: Move data stack to thread from FrameObject. (GH-26076) 2021-05-21 10:57:35 +01:00
pycore_runtime.h bpo-42882: _PyRuntimeState_Init() leaves unicode next_index unchanged (GH-24193) 2021-01-12 10:29:45 +01:00
pycore_structseq.h bpo-43916: Move the _PyStructSequence_InitType function to the internal API (GH-25854) 2021-05-03 15:50:24 +01:00
pycore_symtable.h bpo-42725: Render annotations effectless on symbol table with PEP 563 (GH-25583) 2021-05-03 10:43:00 +03:00
pycore_sysmodule.h bpo-38644: Add _PySys_Audit() which takes tstate (GH-19180) 2020-03-26 18:57:32 +01:00
pycore_traceback.h bpo-42923: _Py_DumpExtensionModules() ignores stdlib ext (GH-24254) 2021-01-19 23:35:27 +01:00
pycore_tuple.h bpo-44231: Don't export internal _PyTuple_FromArray() symbol (GH-26352) 2021-05-25 15:58:14 +02:00
pycore_ucnhash.h bpo-42157: Rename unicodedata.ucnhash_CAPI (GH-22994) 2020-10-27 04:36:22 +01:00
pycore_unionobject.h bpo-42233: Add union type expression support for GenericAlias and fix de-duplicating of GenericAlias (GH-23077) 2020-11-08 20:00:13 -08:00
pycore_warnings.h bpo-43268: Pass interp rather than tstate to internal functions (GH-24580) 2021-02-19 15:10:45 +01:00