cpython/Tools
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
..
buildbot bpo-41173: Copy test results file from ARM worker before uploading (GH-21305) 2020-07-08 00:24:39 +01:00
c-analyzer Fix a typo in c-analyzer (GH-24468) 2021-03-19 16:38:12 +09:00
ccbench bpo-43723: Fix deprecation error caused by thread.setDaemon() (GH-25361) 2021-04-12 13:12:36 +02:00
clinic Do not use Py_ssize_clean_t (GH-25940) 2021-05-08 10:17:37 +09:00
demo Minor updates to the vector demo (GH-24853) 2021-03-15 19:53:58 -07:00
freeze bpo-44131: Test Py_FrozenMain() (GH-26126) 2021-05-17 23:48:35 +02:00
gdb bpo-43693: Add new internal code objects fields: co_fastlocalnames and co_fastlocalkinds. (gh-26388) 2021-06-03 10:28:27 -06:00
i18n bpo-36310: Allow pygettext.py to detect calls to gettext in f-strings. (GH-19875) 2020-11-10 01:50:45 +03:00
importbench Tools/importbench: Fix a misplaced stderr= (GH-12690) 2019-04-05 09:18:19 +02:00
iobench Replace KB unit with KiB (#4293) 2017-11-08 14:44:44 -08:00
msi Improve CDN purge script (GH-25251) 2021-04-07 13:14:00 +01:00
nuget bpo-41744: Package python.props with correct name in NuGet package (GH-22154) 2020-09-14 20:30:15 +01:00
peg_generator bpo-44180: Fix edge cases in invalid assigment rules in the parser (GH-26283) 2021-05-21 18:34:54 +01:00
pynche bpo-42630: Improve error reporting in Tkinter for absent default root (GH-23781) 2020-12-19 12:17:08 +02:00
scripts bpo-44125: Fix "make patchcheck" on non-English locale (GH-26102) 2021-05-13 10:48:15 -07:00
ssl bpo-38820: Test with OpenSSL 3.0.0-alpha17 (#26266) 2021-05-20 16:46:38 +02:00
stringbench Issue #19936: Added executable bits or shebang lines to Python scripts which 2014-01-16 17:33:23 +02:00
test2to3 Issue #19936: Remove executable bits from C source files and several forgotten 2014-01-16 18:48:45 +02:00
tz bpo-29919: Remove unused imports found by pyflakes (#137) 2017-03-27 16:05:26 +02:00
unicode bpo-40328: Add tool for generating cjk mapping headers (GH-19602) 2020-04-30 02:34:24 +09:00
unittestgui Remove a redundant assignment in Tools/unittestgui/unittestgui.py (GH-21438) 2021-05-16 16:55:06 +01:00
README bpo-40334: PEP 617 implementation: New PEG parser for CPython (GH-19503) 2020-04-22 23:29:27 +01:00

README

This directory contains a number of Python programs that are useful
while building or extending Python.

buildbot        Batchfiles for running on Windows buildbot workers.

ccbench         A Python threads-based concurrency benchmark. (*)

demo            Several Python programming demos.

freeze          Create a stand-alone executable from a Python program.

gdb             Python code to be run inside gdb, to make it easier to
                debug Python itself (by David Malcolm).

i18n            Tools for internationalization. pygettext.py
                parses Python source code and generates .pot files,
                and msgfmt.py generates a binary message catalog
                from a catalog in text format.

iobench         Benchmark for the new Python I/O system. (*)

msi             Support for packaging Python as an MSI package on Windows.

parser          Un-parsing tool to generate code from an AST.

peg_generator   PEG-based parser generator (pegen) used for new parser.

pynche          A Tkinter-based color editor.

scripts         A number of useful single-file programs, e.g. tabnanny.py
                by Tim Peters, which checks for inconsistent mixing of
                tabs and spaces, and 2to3, which converts Python 2 code
                to Python 3 code.

stringbench     A suite of micro-benchmarks for various operations on
                strings (both 8-bit and unicode). (*)

test2to3        A demonstration of how to use 2to3 transparently in setup.py.

unicode         Tools for generating unicodedata and codecs from unicode.org
                and other mapping files (by Fredrik Lundh, Marc-Andre Lemburg
                and Martin von Loewis).

unittestgui     A Tkinter based GUI test runner for unittest, with test
                discovery.


(*) A generic benchmark suite is maintained separately at https://github.com/python/performance