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'])" python3 -m timeit -s "from subprocess import call" "call(['./python', '-c', 'pass'])"
If this simple check suggests that any changes may pose a performance Current numbers on my system for 2.7, 3.2 and 3.3 (using the 3.3
problem, then a more sophisticated microbenchmark will be developed to assist subprocess and timeit modules to execute the check, all with non-debug
in investigation. 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 Required Configuration Settings
@ -151,7 +175,7 @@ be able to control the following aspects of the final interpreter state:
* ``sys.getfsencoding`` * ``sys.getfsencoding``
* ``os.fsencode`` * ``os.fsencode``
* ``os.fsdecode`` * ``os.fsdecode``
* The IO encoding used by: * The IO encoding (if any) and the buffering used by:
* ``sys.stdin`` * ``sys.stdin``
* ``sys.stdout`` * ``sys.stdout``
* ``sys.stderr`` * ``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. can control this by setting the ``Py_NoUserSiteDirectory`` global variable.
The following commands can be used to check the default path configurations 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 for a given Python executable on a given system:
through ``os.path.abspath``):
* ``./python -m site`` - standard configuration * ``./python -c "import sys, pprint; pprint.pprint(sys.path)"``
* ``./python -s -m site`` - user site directory disabled - standard configuration
* ``./python -S -m site`` - all site path modifications disabled * ``./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 (Note: you can see similar information using ``-m site`` instead of ``-c``,
desired effect, as the explicit import of the site module will still make but this is slightly misleading as it calls ``os.abspath`` on all of the
the implicit path modifications that should have been disabled by the ``-S`` path entries (making relative path entries look absolute), and also causes
option. The command problems in the last case, as on Python versions prior to 3.3, explicitly
``./python -S -c "import sys, pprint; pprint.pprint(sys.path)"`` will importing site will carry out the path modifications ``-S`` avoids, while on
display the desired information. That command can also be used to see 3.3+ combining ``-m site`` with ``-S`` currently fails)
the raw path entries without the ``os.path.abspath`` calls)
The calculation of ``sys.path[0]`` is comparatively straightforward: 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: * The initial warning system state:
* ``sys.warnoptions`` * ``sys.warnoptions``
* (-W option, PYTHONWARNINGS)
* Arbitrary extended options (e.g. to automatically enable ``faulthandler``): * Arbitrary extended options (e.g. to automatically enable ``faulthandler``):
* ``sys._xoptions`` * ``sys._xoptions``
* (-X option)
* The filesystem encoding used by: * The filesystem encoding used by:
* ``sys.getfsencoding`` * ``sys.getfsencoding``
* ``os.fsencode`` * ``os.fsencode``
* ``os.fsdecode`` * ``os.fsdecode``
* The IO encoding used by: * The IO encoding and buffering used by:
* ``sys.stdin`` * ``sys.stdin``
* ``sys.stdout`` * ``sys.stdout``
* ``sys.stderr`` * ``sys.stderr``
* (-u option, PYTHONIOENCODING, PYTHONUNBUFFEREDIO)
* Whether or not to implicitly cache bytecode files: * Whether or not to implicitly cache bytecode files:
* ``sys.dont_write_bytecode`` * ``sys.dont_write_bytecode``
* (-B option, PYTHONDONTWRITEBYTECODE)
* Whether or not to enforce correct case in filenames on case-insensitive * Whether or not to enforce correct case in filenames on case-insensitive
platforms platforms
* ``os.environ["PYTHONCASEOK"]`` * ``os.environ["PYTHONCASEOK"]``
@ -400,15 +429,15 @@ Much of the configuration of CPython is currently handled through C level
global variables:: global variables::
Py_BytesWarningFlag Py_BytesWarningFlag
Py_DebugFlag Py_DebugFlag (-d option)
Py_InspectFlag Py_InspectFlag (-i option, PYTHONINSPECT)
Py_InteractiveFlag Py_InteractiveFlag
Py_OptimizeFlag Py_OptimizeFlag (-O option, PYTHONOPTIMIZE)
Py_DontWriteBytecodeFlag Py_DontWriteBytecodeFlag (-B option, PYTHONDONTWRITEBYTECODE)
Py_NoUserSiteDirectory Py_NoUserSiteDirectory (-s option, PYTHONNOUSERSITE)
Py_NoSiteFlag Py_NoSiteFlag (-S option)
Py_UnbufferedStdioFlag Py_UnbufferedStdioFlag
Py_VerboseFlag Py_VerboseFlag (-v option, PYTHONVERBOSE)
For the above variables, the conversion of command line options and For the above variables, the conversion of command line options and
environment variables to C global variables is handled by ``Py_Main``, 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 banner) is triggered only when standard input is reported as a terminal
connection by the operating system. 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_] Also see detailed sequence of operations notes at [1_]