More PEP 432 updates

- avoid "-m site" when describing how to explore sys.path
- provide example startup times for 2.7, 3.2 and 3.3 on my system
- misc notes on things to be documented about the status quo
This commit is contained in:
Nick Coghlan 2012-12-29 18:55:47 +10:00
parent 3b72e78196
commit 1be4a026ed
1 changed files with 56 additions and 24 deletions

View File

@ -124,9 +124,33 @@ tear down the interpreter::
python3 -m timeit -s "from subprocess import call" "call(['./python', '-c', 'pass'])"
If this simple check suggests that any changes may pose a performance
problem, then a more sophisticated microbenchmark will be developed to assist
in investigation.
Current numbers on my system for 2.7, 3.2 and 3.3 (using the 3.3
subprocess and timeit modules to execute the check, all with non-debug
builds)::
# Python 2.7
$ py33/python -m timeit -s "from subprocess import call" "call(['py27/python', '-c', 'pass'])"
100 loops, best of 3: 17.8 msec per loop
# Python 3.2
$ py33/python -m timeit -s "from subprocess import call" "call(['py32/python', '-c', 'pass'])"
10 loops, best of 3: 39 msec per loop
# Python 3.3
$ py33/python -m timeit -s "from subprocess import call" "call(['py33/python', '-c', 'pass'])"
10 loops, best of 3: 25.3 msec per loop
Improvements in the import system and the Unicode support already resulted
in a more than 30% improvement in startup time in Python 3.3 relative to
3.2. Python 3.3 is still slightly slower to start than Python 2.7 due to the
additional infrastructure that needs to be put in place to support the Unicode
based text model.
This PEP is not expected to have any significant effect on the startup time,
as it is aimed primarily at *reordering* the existing initialisation
sequence, without making substantial changes to the individual steps.
However, if this simple check suggests that the proposed changes to the
initialisation sequence may pose a performance problem, then a more
sophisticated microbenchmark will be developed to assist in investigation.
Required Configuration Settings
@ -151,7 +175,7 @@ be able to control the following aspects of the final interpreter state:
* ``sys.getfsencoding``
* ``os.fsencode``
* ``os.fsdecode``
* The IO encoding used by:
* The IO encoding (if any) and the buffering used by:
* ``sys.stdin``
* ``sys.stdout``
* ``sys.stderr``
@ -297,20 +321,21 @@ directory from the list of directories added. Embedding applications
can control this by setting the ``Py_NoUserSiteDirectory`` global variable.
The following commands can be used to check the default path configurations
for a given Python executable on a given system (after passing the entries
through ``os.path.abspath``):
for a given Python executable on a given system:
* ``./python -m site`` - standard configuration
* ``./python -s -m site`` - user site directory disabled
* ``./python -S -m site`` - all site path modifications disabled
* ``./python -c "import sys, pprint; pprint.pprint(sys.path)"``
- standard configuration
* ``./python -s -c "import sys, pprint; pprint.pprint(sys.path)"``
- user site directory disabled
* ``./python -S -c "import sys, pprint; pprint.pprint(sys.path)"``
- all site path modifications disabled
(Note: on Python versions prior to 3.3, the last command won't have the
desired effect, as the explicit import of the site module will still make
the implicit path modifications that should have been disabled by the ``-S``
option. The command
``./python -S -c "import sys, pprint; pprint.pprint(sys.path)"`` will
display the desired information. That command can also be used to see
the raw path entries without the ``os.path.abspath`` calls)
(Note: you can see similar information using ``-m site`` instead of ``-c``,
but this is slightly misleading as it calls ``os.abspath`` on all of the
path entries (making relative path entries look absolute), and also causes
problems in the last case, as on Python versions prior to 3.3, explicitly
importing site will carry out the path modifications ``-S`` avoids, while on
3.3+ combining ``-m site`` with ``-S`` currently fails)
The calculation of ``sys.path[0]`` is comparatively straightforward:
@ -365,18 +390,22 @@ TBD: Cover the initialisation of the following in more detail:
* The initial warning system state:
* ``sys.warnoptions``
* (-W option, PYTHONWARNINGS)
* Arbitrary extended options (e.g. to automatically enable ``faulthandler``):
* ``sys._xoptions``
* (-X option)
* The filesystem encoding used by:
* ``sys.getfsencoding``
* ``os.fsencode``
* ``os.fsdecode``
* The IO encoding used by:
* The IO encoding and buffering used by:
* ``sys.stdin``
* ``sys.stdout``
* ``sys.stderr``
* (-u option, PYTHONIOENCODING, PYTHONUNBUFFEREDIO)
* Whether or not to implicitly cache bytecode files:
* ``sys.dont_write_bytecode``
* (-B option, PYTHONDONTWRITEBYTECODE)
* Whether or not to enforce correct case in filenames on case-insensitive
platforms
* ``os.environ["PYTHONCASEOK"]``
@ -400,15 +429,15 @@ Much of the configuration of CPython is currently handled through C level
global variables::
Py_BytesWarningFlag
Py_DebugFlag
Py_InspectFlag
Py_DebugFlag (-d option)
Py_InspectFlag (-i option, PYTHONINSPECT)
Py_InteractiveFlag
Py_OptimizeFlag
Py_DontWriteBytecodeFlag
Py_NoUserSiteDirectory
Py_NoSiteFlag
Py_OptimizeFlag (-O option, PYTHONOPTIMIZE)
Py_DontWriteBytecodeFlag (-B option, PYTHONDONTWRITEBYTECODE)
Py_NoUserSiteDirectory (-s option, PYTHONNOUSERSITE)
Py_NoSiteFlag (-S option)
Py_UnbufferedStdioFlag
Py_VerboseFlag
Py_VerboseFlag (-v option, PYTHONVERBOSE)
For the above variables, the conversion of command line options and
environment variables to C global variables is handled by ``Py_Main``,
@ -428,6 +457,9 @@ Finally, some interactive behaviour (such as printing the introductory
banner) is triggered only when standard input is reported as a terminal
connection by the operating system.
TBD: Document how the "-x" option is handled (skips processing of the
first comment line in the main script)
Also see detailed sequence of operations notes at [1_]